Skip to content

Commit 10c16dd

Browse files
authored
Merge pull request #4 from felixheck/release/1.0.0
Release/1.0.0
2 parents 5a88f49 + 4d83562 commit 10c16dd

File tree

6 files changed

+181
-220
lines changed

6 files changed

+181
-220
lines changed

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@
5151
"lodash": "^4.17.4"
5252
},
5353
"peerDependencies": {
54-
"hapi": ">= 13.x.x",
55-
"hapi-pino": ">= 1.6.x"
54+
"hapi": ">= 13.x.x"
5655
},
5756
"engines": {
5857
"node": ">=6.0.0",

src/utils.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ const joi = require('joi')
1010
const scheme = joi.object({
1111
client: joi.object({
1212
realmUrl: joi.string().uri().required(),
13-
clientId: joi.string().required()
13+
clientId: joi.string().min(1).required(),
14+
secret: joi.string().min(1).required()
1415
}).unknown(true).required(),
1516
cache: joi.alternatives().try(joi.object({
1617
segment: joi.string().default('keycloakJwt')

test/_fixtures.js

Lines changed: 20 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,34 @@
11
const token = 'abc.def.ghi'
22
const realmUrl = 'https://localhost:8080/auth/realms/testme'
33
const clientId = 'foobar'
4+
const secret = '1234-bar-4321-foo'
45

56
/**
67
* @type Object
78
* @public
89
*
910
* Client config
1011
*/
11-
const config = {
12+
const clientConfig = {
1213
realmUrl,
1314
clientId,
14-
secret: 'barfoo'
15+
secret
1516
}
1617

18+
/**
19+
* @type Object
20+
* @public
21+
*
22+
* Common attributes
23+
*/
24+
const common = Object.assign({}, clientConfig, { token })
25+
26+
/**
27+
* @type Object
28+
* @public
29+
*
30+
* Content Parts of JWTs
31+
*/
1732
const content = {
1833
userData: {
1934
'exp': 5,
@@ -61,74 +76,9 @@ const jwt = {
6176
userDataScope: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjUsImlhdCI6MSwic3ViIjoiMTIzNDU2Nzg5MCIsIm5hbWUiOiJKb2huIERvZSIsImVtYWlsIjoiam9obi5kb2VAbWFpbC5jb20iLCJhZG1pbiI6dHJ1ZX0.2tfThhgwSbIEq2cZcoHSRwL2-UCanF23BXlyphm5ehs'
6277
}
6378

64-
/**
65-
* @type Object
66-
* @public
67-
*
68-
* Succeeded validations response
69-
*/
70-
const validation = {
71-
'jti': '918c5d0e-1924-40e3-9fc6-b5cfd0016e1a',
72-
'exp': Date.now() * 1000 + 60000,
73-
'nbf': 0,
74-
'iat': Date.now() * 1000,
75-
'iss': 'https://localhost:8080/auth/realms/testme',
76-
'aud': 'testme-app',
77-
'sub': '5b220cee-48c2-47b9-8c53-2cac94eed51d',
78-
'typ': 'Bearer',
79-
'azp': 'testme-app',
80-
'auth_time': 0,
81-
'session_state':
82-
'08f140bb-7801-47c1-9202-3d8a805e359a',
83-
'name': 'Foo Bar',
84-
'preferred_username': 'foobar',
85-
'given_name': 'Foo',
86-
'family_name': 'Bar',
87-
'email': '[email protected]',
88-
'acr': '1',
89-
'client_session': '8d36c537-1d12-4c47-8032-cfd26d0133b0',
90-
'allowed-origins': [],
91-
'realm_access': {
92-
'roles': ['admin']
93-
},
94-
'resource_access': {
95-
'other-app': {
96-
'roles': ['other-app:creator']
97-
},
98-
'testme-app': {
99-
'roles': ['editor']
100-
},
101-
'account': {
102-
'roles': ['manage-account', 'manage-account-links', 'view-profile']
103-
}
104-
},
105-
'client_id': 'testme-app',
106-
'username': 'foobar',
107-
'active': true
108-
}
109-
110-
/**
111-
* @type Object
112-
* @public
113-
*
114-
* Succeeded userInfo response
115-
*/
116-
const userInfo = {
117-
'sub': '5b220cee-48c2-47b9-8c53-2cac94eed51d',
118-
'name': 'Foo Bar',
119-
'preferred_username': 'foobar',
120-
'given_name': 'Foo',
121-
'family_name': 'Bar',
122-
'email': '[email protected]'
123-
}
124-
12579
module.exports = {
126-
token,
127-
realmUrl,
128-
clientId,
129-
config,
80+
common,
81+
clientConfig,
13082
content,
131-
jwt,
132-
validation,
133-
userInfo
83+
jwt
13484
}

test/_helpers.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ const GrantManagerClone = {}
1313
* The default plugin configuration
1414
*/
1515
const defaults = {
16-
client: fixtures.config,
17-
cache: false
16+
client: fixtures.clientConfig,
17+
cache: false,
18+
userInfo: undefined
1819
}
1920

2021
/**

test/index.spec.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ test.cb.serial('throw error if plugin gets registered twice', (t) => {
2020
})
2121

2222
test.cb.serial('authentication does succeed', (t) => {
23-
prototypes.stub('validateAccessToken', fixtures.validation)
23+
prototypes.stub('validateAccessToken', fixtures.content.userData)
2424

2525
getServer(undefined, (server) => {
2626
server.inject({
@@ -38,7 +38,7 @@ test.cb.serial('authentication does succeed', (t) => {
3838
})
3939

4040
test.cb.serial('authentication does succeed – cached', (t) => {
41-
prototypes.stub('validateAccessToken', fixtures.validation)
41+
prototypes.stub('validateAccessToken', fixtures.content.userData)
4242

4343
const mockReq = {
4444
method: 'GET',
@@ -49,7 +49,7 @@ test.cb.serial('authentication does succeed – cached', (t) => {
4949
}
5050

5151
getServer({
52-
client: fixtures.config,
52+
client: fixtures.clientConfig,
5353
cache: {}
5454
}, (server) => {
5555
server.inject(mockReq, () => {
@@ -63,7 +63,7 @@ test.cb.serial('authentication does succeed – cached', (t) => {
6363
})
6464

6565
test.cb.serial('authentication does success – valid roles', (t) => {
66-
prototypes.stub('validateAccessToken', fixtures.validation)
66+
prototypes.stub('validateAccessToken', fixtures.content.userData)
6767

6868
getServer(undefined, (server) => {
6969
server.inject({
@@ -81,7 +81,7 @@ test.cb.serial('authentication does success – valid roles', (t) => {
8181
})
8282

8383
test.cb.serial('authentication does fail – invalid roles', (t) => {
84-
prototypes.stub('validateAccessToken', fixtures.validation)
84+
prototypes.stub('validateAccessToken', fixtures.content.userData)
8585

8686
getServer(undefined, (server) => {
8787
server.inject({
@@ -123,7 +123,7 @@ test.cb.serial('authentication does fail – invalid header', (t) => {
123123
method: 'GET',
124124
url: '/',
125125
headers: {
126-
authorization: fixtures.token
126+
authorization: fixtures.common.token
127127
}
128128
}, (res) => {
129129
t.truthy(res)
@@ -135,7 +135,7 @@ test.cb.serial('authentication does fail – invalid header', (t) => {
135135
})
136136

137137
test.cb.serial('server method validates token', (t) => {
138-
prototypes.stub('validateAccessToken', fixtures.validation)
138+
prototypes.stub('validateAccessToken', fixtures.content.userData)
139139

140140
getServer(undefined, (server) => {
141141
server.kjwt.validate(`bearer ${fixtures.jwt.userData}`, (err, res) => {

0 commit comments

Comments
 (0)