Skip to content

Commit

Permalink
cleanup fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
felixheck committed Aug 1, 2017
1 parent 702e499 commit 4abb999
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 165 deletions.
88 changes: 18 additions & 70 deletions test/_fixtures.js
Expand Up @@ -9,12 +9,26 @@ const secret = '1234-bar-4321-foo'
*
* Client config
*/
const config = {
const clientConfig = {
realmUrl,
clientId,
secret
}

/**
* @type Object
* @public
*
* Common attributes
*/
const common = Object.assign({}, clientConfig, { token })

/**
* @type Object
* @public
*
* Content Parts of JWTs
*/
const content = {
userData: {
'exp': 5,
Expand Down Expand Up @@ -62,75 +76,9 @@ const jwt = {
userDataScope: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjUsImlhdCI6MSwic3ViIjoiMTIzNDU2Nzg5MCIsIm5hbWUiOiJKb2huIERvZSIsImVtYWlsIjoiam9obi5kb2VAbWFpbC5jb20iLCJhZG1pbiI6dHJ1ZX0.2tfThhgwSbIEq2cZcoHSRwL2-UCanF23BXlyphm5ehs'
}

/**
* @type Object
* @public
*
* Succeeded validations response
*/
const validation = {
'jti': '918c5d0e-1924-40e3-9fc6-b5cfd0016e1a',
'exp': Date.now() * 1000 + 60000,
'nbf': 0,
'iat': Date.now() * 1000,
'iss': 'https://localhost:8080/auth/realms/testme',
'aud': 'testme-app',
'sub': '5b220cee-48c2-47b9-8c53-2cac94eed51d',
'typ': 'Bearer',
'azp': 'testme-app',
'auth_time': 0,
'session_state':
'08f140bb-7801-47c1-9202-3d8a805e359a',
'name': 'Foo Bar',
'preferred_username': 'foobar',
'given_name': 'Foo',
'family_name': 'Bar',
'email': 'foo.bar@42.com',
'acr': '1',
'client_session': '8d36c537-1d12-4c47-8032-cfd26d0133b0',
'allowed-origins': [],
'realm_access': {
'roles': ['admin']
},
'resource_access': {
'other-app': {
'roles': ['other-app:creator']
},
'testme-app': {
'roles': ['editor']
},
'account': {
'roles': ['manage-account', 'manage-account-links', 'view-profile']
}
},
'client_id': 'testme-app',
'username': 'foobar',
'active': true
}

/**
* @type Object
* @public
*
* Succeeded userInfo response
*/
const userInfo = {
'sub': '5b220cee-48c2-47b9-8c53-2cac94eed51d',
'name': 'Foo Bar',
'preferred_username': 'foobar',
'given_name': 'Foo',
'family_name': 'Bar',
'email': 'foo.bar@42.com'
}

module.exports = {
token,
realmUrl,
clientId,
secret,
config,
common,
clientConfig,
content,
jwt,
validation,
userInfo
jwt
}
5 changes: 3 additions & 2 deletions test/_helpers.js
Expand Up @@ -13,8 +13,9 @@ const GrantManagerClone = {}
* The default plugin configuration
*/
const defaults = {
client: fixtures.config,
cache: false
client: fixtures.clientConfig,
cache: false,
userInfo: undefined
}

/**
Expand Down
14 changes: 7 additions & 7 deletions test/index.spec.js
Expand Up @@ -20,7 +20,7 @@ test.cb.serial('throw error if plugin gets registered twice', (t) => {
})

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

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

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

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

getServer({
client: fixtures.config,
client: fixtures.clientConfig,
cache: {}
}, (server) => {
server.inject(mockReq, () => {
Expand All @@ -63,7 +63,7 @@ test.cb.serial('authentication does succeed – cached', (t) => {
})

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

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

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

getServer(undefined, (server) => {
server.inject({
Expand Down Expand Up @@ -123,7 +123,7 @@ test.cb.serial('authentication does fail – invalid header', (t) => {
method: 'GET',
url: '/',
headers: {
authorization: fixtures.token
authorization: fixtures.common.token
}
}, (res) => {
t.truthy(res)
Expand All @@ -135,7 +135,7 @@ test.cb.serial('authentication does fail – invalid header', (t) => {
})

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

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

0 comments on commit 4abb999

Please sign in to comment.