Skip to content

Commit 2530359

Browse files
committed
add helpers for api key tests
1 parent 1fd2dc5 commit 2530359

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

test/_helpers.js

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,19 @@ function mockEntitlement (code, data, isError = false) {
6161
isError ? base.replyWithError(data) : base.reply(code, data)
6262
}
6363

64+
/**
65+
* @function
66+
* @public
67+
*
68+
* Mock request to the api key service.
69+
*
70+
* @param {number} code The status code to be returned
71+
* @param {Object} data The response object to be returned
72+
*/
73+
function mockApiKey (code, data) {
74+
nock('http://barfoo.com').get('/foo/bar').reply(code, data)
75+
}
76+
6477
/**
6578
* @function
6679
* @public
@@ -108,7 +121,7 @@ function registerRoutes (server) {
108121
{
109122
method: 'GET',
110123
path: '/',
111-
config: {
124+
options: {
112125
auth: 'keycloak-jwt',
113126
handler (req) {
114127
return req.auth.credentials.scope
@@ -118,7 +131,7 @@ function registerRoutes (server) {
118131
{
119132
method: 'GET',
120133
path: '/role',
121-
config: {
134+
options: {
122135
auth: {
123136
strategies: ['keycloak-jwt'],
124137
access: {
@@ -133,7 +146,7 @@ function registerRoutes (server) {
133146
{
134147
method: 'GET',
135148
path: '/role/guest',
136-
config: {
149+
options: {
137150
auth: {
138151
strategies: ['keycloak-jwt'],
139152
access: {
@@ -148,7 +161,7 @@ function registerRoutes (server) {
148161
{
149162
method: 'GET',
150163
path: '/role/rpt',
151-
config: {
164+
options: {
152165
auth: {
153166
strategies: ['keycloak-jwt'],
154167
access: {
@@ -159,6 +172,18 @@ function registerRoutes (server) {
159172
return req.auth.credentials.scope
160173
}
161174
}
175+
},
176+
{
177+
method: 'GET',
178+
path: '/proxy',
179+
options: {
180+
handler (req) {
181+
return {
182+
headers: req.headers,
183+
query: req.query
184+
}
185+
}
186+
}
162187
}
163188
])
164189
}
@@ -199,6 +224,7 @@ async function getServer (options) {
199224
await server.initialize()
200225

201226
if (options === false) {
227+
registerRoutes(server)
202228
return server
203229
}
204230

@@ -210,6 +236,7 @@ module.exports = {
210236
mockIntrospect,
211237
mockEntitlement,
212238
mockRequest,
239+
mockApiKey,
213240
log,
214241
getServer,
215242
registerPlugin

0 commit comments

Comments
 (0)