Skip to content

Commit 8b606fb

Browse files
committed
scope tests
1 parent 5af7a9d commit 8b606fb

File tree

2 files changed

+37
-7
lines changed

2 files changed

+37
-7
lines changed

test/_helpers.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,21 @@ function registerRoutes (server) {
6161
{
6262
method: 'GET',
6363
path: '/role',
64+
config: {
65+
auth: {
66+
strategies: ['keycloak-jwt'],
67+
access: {
68+
scope: ['editor']
69+
}
70+
},
71+
handler (req, reply) {
72+
reply({ foo: 42 })
73+
}
74+
}
75+
},
76+
{
77+
method: 'GET',
78+
path: '/role/guest',
6479
config: {
6580
auth: {
6681
strategies: ['keycloak-jwt'],
@@ -109,11 +124,7 @@ function registerPlugin (server, options = defaults, done = () => {}) {
109124
function getServer (options, done) {
110125
const server = new hapi.Server()
111126

112-
server.connection({
113-
host: '127.0.0.1',
114-
port: 1337
115-
})
116-
127+
server.connection()
117128
server.initialize((err) => {
118129
if (err) throw err
119130

test/index.spec.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ test.cb.serial('authentication does succeed – cached', (t) => {
6666
})
6767
})
6868

69-
test.cb.serial('authentication does failinvalid roles', (t) => {
69+
test.cb.serial('authentication does successvalid roles', (t) => {
7070
prototypes.stub('validateAccessToken', fixtures.validation)
7171
prototypes.stub('userInfo', fixtures.userInfo)
7272

@@ -75,7 +75,26 @@ test.cb.serial('authentication does fail – invalid roles', (t) => {
7575
method: 'GET',
7676
url: '/role',
7777
headers: {
78-
authorization: `bearer ${fixtures.jwt.content}`
78+
authorization: `bearer ${fixtures.jwt.userData}`
79+
}
80+
}, (res) => {
81+
t.truthy(res)
82+
t.is(res.statusCode, 200)
83+
t.end()
84+
})
85+
})
86+
})
87+
88+
test.cb.serial('authentication does fail – invalid roles', (t) => {
89+
prototypes.stub('validateAccessToken', fixtures.validation)
90+
prototypes.stub('userInfo', fixtures.userInfo)
91+
92+
helpers.getServer(undefined, (server) => {
93+
server.inject({
94+
method: 'GET',
95+
url: '/role/guest',
96+
headers: {
97+
authorization: `bearer ${fixtures.jwt.userData}`
7998
}
8099
}, (res) => {
81100
t.truthy(res)

0 commit comments

Comments
 (0)