Skip to content

Commit 4c88fc9

Browse files
author
Eric Koleda
committed
Add lint check for client ID in samples.
1 parent 5d5b339 commit 4c88fc9

File tree

4 files changed

+60
-4
lines changed

4 files changed

+60
-4
lines changed

gulpfile.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
1-
const gulp = require('gulp');
21
const concat = require('gulp-concat');
3-
const expose = require('gulp-expose');
2+
const contains = require('gulp-contains');
43
const del = require('del');
5-
const rename = require("gulp-rename");
64
const eslint = require('gulp-eslint');
5+
const expose = require('gulp-expose');
6+
const gulp = require('gulp');
7+
const rename = require("gulp-rename");
8+
9+
// Regex that looks for a populated client ID in the code. This is used to
10+
// catch cases where the client ID is accidentally committed in a sample.
11+
const CLIENT_ID_REGEX = /CLIENT_ID\s*=\s*'[^.']/;
12+
13+
// String which if it appears in the source code bypasses the client ID check.
14+
// This is to allow samples that use a publicly-available demo client ID to
15+
// not trigger the error.
16+
const CLIENT_ID_BYPASS = '@credentialsOK';
717

818
gulp.task('clean', async function() {
919
return del([
@@ -22,5 +32,14 @@ gulp.task('lint', () => {
2232
return gulp.src(['src/*.js', 'samples/*.gs', 'test/**/*.js', '!node_modules/**'])
2333
.pipe(eslint())
2434
.pipe(eslint.format())
25-
.pipe(eslint.failAfterError());
35+
.pipe(eslint.failAfterError())
36+
.pipe(contains({
37+
search: CLIENT_ID_REGEX,
38+
onFound: (string, file, cb) => {
39+
if (file.contents.toString().includes(CLIENT_ID_BYPASS)) {
40+
return false;
41+
}
42+
return cb(`Client ID found in file: "${file.relative}"`);
43+
}
44+
}));
2645
});

package-lock.json

Lines changed: 35 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"gulp": "^4.0.2",
2525
"gulp-clean": "^0.4.0",
2626
"gulp-concat": "^2.6.1",
27+
"gulp-contains": "^1.2.0",
2728
"gulp-eslint": "^4.0.2",
2829
"gulp-expose": "0.0.7",
2930
"gulp-rename": "^1.4.0",

samples/IdentityServer4.gs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*/
99

1010
// Test credentials for the Demo API.
11+
// @credentialsOK
1112
var CLIENT_ID = 'server.code';
1213
var CLIENT_SECRET = 'secret';
1314

0 commit comments

Comments
 (0)