Skip to content

Commit 858e689

Browse files
committed
add some minor karma tests to run in real browsers
1 parent 1a7ad61 commit 858e689

6 files changed

Lines changed: 380 additions & 1 deletion

File tree

‎bower.json‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "oidc-client-node-sample",
3+
"description": "",
4+
"main": "server.js",
5+
"authors": [
6+
"Brock Allen <brockallen@gmail.com>"
7+
],
8+
"license": "ISC",
9+
"moduleType": [],
10+
"homepage": "",
11+
"ignore": [
12+
"**/.*",
13+
"node_modules",
14+
"bower_components",
15+
"test",
16+
"tests"
17+
],
18+
"dependencies": {
19+
"kjur-jsrsasign": "jsrsasign#^5.0.7"
20+
}
21+
}

‎karma.conf.js‎

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// Karma configuration
2+
// Generated on Wed Mar 30 2016 23:37:14 GMT-0400 (Eastern Daylight Time)
3+
4+
module.exports = function(config) {
5+
config.set({
6+
7+
// base path that will be used to resolve all patterns (eg. files, exclude)
8+
basePath: '',
9+
10+
11+
// frameworks to use
12+
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
13+
frameworks: ['mocha'],
14+
15+
16+
// list of files / patterns to load in the browser
17+
files: [
18+
'node_modules/babel-polyfill/dist/polyfill.js',
19+
'bower_components/kjur-jsrsasign/lib/jsrsasign-5.0.7-all-min.js',
20+
'dist/IdentityModel.js',
21+
'test/integration/assert.js',
22+
'test/integration/oidc.js',
23+
'test/integration/*.spec.js',
24+
],
25+
26+
27+
// list of files to exclude
28+
exclude: [
29+
],
30+
31+
32+
// preprocess matching files before serving them to the browser
33+
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
34+
preprocessors: {
35+
},
36+
37+
38+
// test results reporter to use
39+
// possible values: 'dots', 'progress'
40+
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
41+
reporters: ['progress'],
42+
43+
44+
// web server port
45+
port: 9876,
46+
47+
48+
// enable / disable colors in the output (reporters and logs)
49+
colors: true,
50+
51+
52+
// level of logging
53+
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
54+
logLevel: config.LOG_INFO,
55+
56+
57+
// enable / disable watching file and executing tests whenever any file changes
58+
autoWatch: true,
59+
60+
61+
// start these browsers
62+
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
63+
browsers: [
64+
//'PhantomJS',
65+
//'Chrome',
66+
'Chrome', 'IE', 'Firefox'
67+
],
68+
69+
// Continuous Integration mode
70+
// if true, Karma captures browsers, runs the tests and exits
71+
singleRun: false,
72+
73+
// Concurrency level
74+
// how many browser should be started simultaneous
75+
concurrency: Infinity
76+
})
77+
}

‎package.json‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"description": "OpenID Connect (OIDC) client library",
55
"main": "src/_index.js",
66
"scripts": {
7+
"start": "node sample/server.js",
78
"build": "webpack --config webpack.config.js",
89
"test": "mocha --compilers js:babel-register test/unit/*.spec.js"
910
},
@@ -21,10 +22,21 @@
2122
"babel-core": "^6.7.2",
2223
"babel-loader": "^6.2.4",
2324
"babel-plugin-add-module-exports": "^0.1.2",
25+
"babel-polyfill": "^6.7.4",
2426
"babel-preset-es2015": "^6.6.0",
2527
"babel-register": "^6.7.2",
26-
"mocha": "^2.4.5",
28+
"bower": "^1.7.7",
2729
"chai": "^3.5.0",
30+
"express": "^4.13.4",
31+
"karma": "^0.13.22",
32+
"karma-mocha": "^0.2.2",
33+
"karma-chrome-launcher": "^0.2.3",
34+
"karma-firefox-launcher": "^0.1.7",
35+
"karma-phantomjs-launcher": "^1.0.0",
36+
"karma-ie-launcher": "^0.2.0",
37+
"phantomjs-prebuilt": "^2.1.7",
38+
"mocha": "^2.4.5",
39+
"open": "0.0.5",
2840
"webpack": "^1.12.14"
2941
},
3042
"dependencies": {
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
IdentityModel.Log.logger = console;
2+
3+
window.sessionStorage.clear();
4+
window.localStorage.clear();
5+
6+
describe("OidcClient", function() {
7+
8+
var settings;
9+
var oidcClient;
10+
11+
beforeEach(function() {
12+
IdentityModel.Log.level = IdentityModel.Log.NONE;
13+
14+
settings = {
15+
authority: 'http://localhost:5000/oidc',
16+
metadata: oidc.metadata,
17+
signingKeys: oidc.signingKeys,
18+
19+
client_id: 'js.tokenmanager',
20+
redirect_uri: 'http://localhost:5000/index.html',
21+
post_logout_redirect_uri: 'http://localhost:5000/index.html',
22+
response_type: 'id_token token',
23+
scope: 'openid email roles',
24+
25+
filterProtocolClaims: true,
26+
loadUserInfo: false
27+
};
28+
29+
oidcClient = new IdentityModel.OidcClient(settings);
30+
});
31+
32+
it("should perform signin", function(done) {
33+
34+
oidcClient.createSigninRequest({data:{foo:1}}).then(function(req){
35+
36+
var url = oidc.processAuthorization(req.url);
37+
38+
oidcClient.processSigninResponse(url).then(function(res){
39+
40+
assert(res, "result");
41+
assert(res.state, "res.result");
42+
assert(res.state.foo === 1, "foo===1");
43+
44+
done();
45+
}, function(e){
46+
fail(e);
47+
});
48+
}, function(e){
49+
fail(e);
50+
});
51+
});
52+
53+
it("should perform signout", function(done) {
54+
55+
oidcClient.createSignoutRequest({data:{foo:1}}).then(function(req){
56+
57+
var url = oidc.processEndSession(req.url);
58+
59+
oidcClient.processSignoutResponse(url).then(function(res){
60+
61+
assert(res, "result");
62+
assert(res.state, "res.result");
63+
assert(res.state.foo === 1, "foo===1");
64+
65+
done();
66+
}, function(e){
67+
fail(e);
68+
});
69+
}, function(e){
70+
fail(e);
71+
});
72+
});
73+
});

‎test/integration/assert.js‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function assert(test, msg){
2+
if (!test){
3+
var err = new Error(msg||test);
4+
throw err;
5+
}
6+
}
7+
8+
function fail(e){
9+
if (e instanceof Error){
10+
throw e;
11+
}
12+
throw new Error(e);
13+
}

0 commit comments

Comments
 (0)