Skip to content

Commit 4abb999

Browse files
committed
cleanup fixtures
1 parent 702e499 commit 4abb999

File tree

4 files changed

+114
-165
lines changed

4 files changed

+114
-165
lines changed

test/_fixtures.js

Lines changed: 18 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,26 @@ const secret = '1234-bar-4321-foo'
99
*
1010
* Client config
1111
*/
12-
const config = {
12+
const clientConfig = {
1313
realmUrl,
1414
clientId,
1515
secret
1616
}
1717

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+
*/
1832
const content = {
1933
userData: {
2034
'exp': 5,
@@ -62,75 +76,9 @@ const jwt = {
6276
userDataScope: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjUsImlhdCI6MSwic3ViIjoiMTIzNDU2Nzg5MCIsIm5hbWUiOiJKb2huIERvZSIsImVtYWlsIjoiam9obi5kb2VAbWFpbC5jb20iLCJhZG1pbiI6dHJ1ZX0.2tfThhgwSbIEq2cZcoHSRwL2-UCanF23BXlyphm5ehs'
6377
}
6478

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

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)