Skip to content

Commit 332f340

Browse files
authored
Merge branch 'expert/pubsub' into expert-agent-creds-fe
2 parents afba2e5 + 3fdd67b commit 332f340

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

test/unit/forge/routes/api/user_spec.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,4 +1181,60 @@ describe('User API', async function () {
11811181
response.statusCode.should.equal(404)
11821182
})
11831183
})
1184+
1185+
describe('User Expert Creds', async function () {
1186+
beforeEach(async function () {
1187+
await setupUsers()
1188+
})
1189+
it('user can request expert credentials', async function () {
1190+
// /api/v1/user/expert-creds
1191+
await login('elvis', 'eePassword')
1192+
const response = await app.inject({
1193+
method: 'POST',
1194+
url: '/api/v1/user/expert-creds',
1195+
cookies: { sid: TestObjects.tokens.elvis },
1196+
body: {
1197+
sessionId: 'abcd1234'
1198+
}
1199+
})
1200+
response.statusCode.should.equal(200)
1201+
const json = response.json()
1202+
json.should.only.have.keys('url', 'username', 'password')
1203+
json.should.have.property('url', ':test:')
1204+
json.should.have.property('username', `expert-client:${TestObjects.elvis.hashid}:abcd1234`)
1205+
json.should.have.property('password').and.match(/^ffbec_/)
1206+
})
1207+
it('user cannot request expert credentials without sessionId', async function () {
1208+
await login('elvis', 'eePassword')
1209+
const response = await app.inject({
1210+
method: 'POST',
1211+
url: '/api/v1/user/expert-creds',
1212+
cookies: { sid: TestObjects.tokens.elvis },
1213+
body: {}
1214+
})
1215+
response.statusCode.should.equal(400)
1216+
})
1217+
it('user cannot request expert credentials with invalid sessionId', async function () {
1218+
await login('elvis', 'eePassword')
1219+
const response = await app.inject({
1220+
method: 'POST',
1221+
url: '/api/v1/user/expert-creds',
1222+
cookies: { sid: TestObjects.tokens.elvis },
1223+
body: {
1224+
sessionId: '1' // too short
1225+
}
1226+
})
1227+
response.statusCode.should.equal(400)
1228+
})
1229+
it('user cannot request expert credentials if not logged in', async function () {
1230+
const response = await app.inject({
1231+
method: 'POST',
1232+
url: '/api/v1/user/expert-creds',
1233+
body: {
1234+
sessionId: 'abcd1234'
1235+
}
1236+
})
1237+
response.statusCode.should.equal(401)
1238+
})
1239+
})
11841240
})

0 commit comments

Comments
 (0)