Skip to content

Commit 0322aee

Browse files
committed
Most tests work
1 parent 93de45e commit 0322aee

File tree

5 files changed

+105
-29
lines changed

5 files changed

+105
-29
lines changed

test/integration/authentication-oidc-test.js

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,9 @@ describe('Authentication API (OIDC)', () => {
526526
let authorizationUri, loginUri, authParams, callbackUri
527527
let loginFormFields = ''
528528
let bearerToken
529+
let postLoginUri
530+
let cookie
531+
let postConsentUri
529532

530533
before(() => {
531534
auth = new SolidAuthOIDC({ store: localStorage, window: { location: {} } })
@@ -627,25 +630,50 @@ describe('Authentication API (OIDC)', () => {
627630
})
628631
.then(res => {
629632
expect(res.status).to.equal(302)
630-
let postLoginUri = res.headers.get('location')
631-
let cookie = res.headers.get('set-cookie')
633+
postLoginUri = res.headers.get('location')
634+
cookie = res.headers.get('set-cookie')
632635

633636
// Successful login gets redirected back to /authorize and then
634637
// back to app
635-
expect(postLoginUri.startsWith(aliceServerUri + '/authorize'))
638+
expect(postLoginUri.startsWith(aliceServerUri + '/consent'))
636639
.to.be.true()
637-
638-
return fetch(postLoginUri, { redirect: 'manual', headers: { cookie } })
639-
})
640-
.then(res => {
641-
// User gets redirected back to original app
642-
expect(res.status).to.equal(302)
643-
callbackUri = res.headers.get('location')
644-
expect(callbackUri.startsWith('https://app.example.com#'))
645640
})
646641
})
647642

648-
// Step 6: Web App extracts tokens from the uri hash fragment, uses
643+
// Step 6: User consents to the app accessing certain things
644+
it('should consent via the /consent form', () => {
645+
loginFormFields += `&access_mode=Read&access_mode=Write&consent=true`
646+
647+
return fetch(aliceServerUri + '/consent', {
648+
method: 'POST',
649+
body: loginFormFields,
650+
redirect: 'manual',
651+
headers: {
652+
'content-type': 'application/x-www-form-urlencoded',
653+
cookie
654+
},
655+
credentials: 'include'
656+
})
657+
.then(res => {
658+
expect(res.status).to.equal(302)
659+
postConsentUri = res.headers.get('location')
660+
// cookie = res.headers.get('set-cookie')
661+
662+
// Successful login gets redirected back to /authorize and then
663+
// back to app
664+
expect(postConsentUri.startsWith(aliceServerUri + '/authorize'))
665+
.to.be.true()
666+
return fetch(postConsentUri, { redirect: 'manual', headers: { cookie } })
667+
})
668+
.then(res => {
669+
// User gets redirected back to original app
670+
expect(res.status).to.equal(302)
671+
callbackUri = res.headers.get('location')
672+
expect(callbackUri.startsWith('https://app.example.com#'))
673+
})
674+
})
675+
676+
// Step 7: Web App extracts tokens from the uri hash fragment, uses
649677
// them to access protected resource
650678
it('should use id token from the callback uri to access shared resource (no origin)', () => {
651679
auth.window.location.href = callbackUri

test/integration/authentication-oidc-with-strict-origins-turned-off-test.js

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,8 @@ describe('Authentication API (OIDC) - With strict origins turned off', () => {
399399
let authorizationUri, loginUri, authParams, callbackUri
400400
let loginFormFields = ''
401401
let bearerToken
402+
let cookie
403+
let postLoginUri
402404

403405
before(() => {
404406
auth = new SolidAuthOIDC({ store: localStorage, window: { location: {} } })
@@ -500,24 +502,50 @@ describe('Authentication API (OIDC) - With strict origins turned off', () => {
500502
})
501503
.then(res => {
502504
expect(res.status).to.equal(302)
503-
let postLoginUri = res.headers.get('location')
504-
let cookie = res.headers.get('set-cookie')
505+
postLoginUri = res.headers.get('location')
506+
cookie = res.headers.get('set-cookie')
505507

506508
// Successful login gets redirected back to /authorize and then
507509
// back to app
508-
expect(postLoginUri.startsWith(aliceServerUri + '/authorize'))
510+
expect(postLoginUri.startsWith(aliceServerUri + '/consent'))
509511
.to.be.true()
510-
511-
return fetch(postLoginUri, { redirect: 'manual', headers: { cookie } })
512-
})
513-
.then(res => {
514-
// User gets redirected back to original app
515-
expect(res.status).to.equal(302)
516-
callbackUri = res.headers.get('location')
517-
expect(callbackUri.startsWith('https://app.example.com#'))
518512
})
519513
})
520514

515+
// Step 6: User consents to the app accessing certain things
516+
it('should consent via the /consent form', () => {
517+
loginFormFields += `&access_mode=Read&access_mode=Write&consent=true`
518+
519+
return fetch(aliceServerUri + '/consent', {
520+
method: 'POST',
521+
body: loginFormFields,
522+
redirect: 'manual',
523+
headers: {
524+
'content-type': 'application/x-www-form-urlencoded',
525+
cookie
526+
},
527+
credentials: 'include'
528+
})
529+
.then(res => {
530+
expect(res.status).to.equal(302)
531+
let postLoginUri = res.headers.get('location')
532+
let cookie = res.headers.get('set-cookie')
533+
534+
// Successful login gets redirected back to /authorize and then
535+
// back to app
536+
expect(postLoginUri.startsWith(aliceServerUri + '/authorize'))
537+
.to.be.true()
538+
539+
return fetch(postLoginUri, { redirect: 'manual', headers: { cookie } })
540+
})
541+
.then(res => {
542+
// User gets redirected back to original app
543+
expect(res.status).to.equal(302)
544+
callbackUri = res.headers.get('location')
545+
expect(callbackUri.startsWith('https://app.example.com#'))
546+
})
547+
})
548+
521549
// Step 6: Web App extracts tokens from the uri hash fragment, uses
522550
// them to access protected resource
523551
it('should use id token from the callback uri to access shared resource (no origin)', () => {
Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1+
@prefix : <#>.
12
@prefix acl: <http://www.w3.org/ns/auth/acl#>.
3+
@prefix c: <card#>.
4+
@prefix c0: <https://localhost:8443/profile/card#>.
25

3-
<#me> acl:trustedApp [ acl:origin <https://trusted.app>;
4-
acl:mode acl:Read, acl:Write, acl:Append, acl:Control].
6+
c:me
7+
acl:trustedApp
8+
[ acl:mode acl:Read, acl:Write; acl:origin <https://app.example.com> ].
9+
c0:me
10+
acl:trustedApp
11+
[
12+
acl:mode acl:Append, acl:Control, acl:Read, acl:Write;
13+
acl:origin <https://trusted.app>
14+
].
Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1+
@prefix : <#>.
12
@prefix acl: <http://www.w3.org/ns/auth/acl#>.
3+
@prefix c: <card#>.
4+
@prefix c0: <https://localhost:8443/profile/card#>.
25

3-
<#me> acl:trustedApp [ acl:origin <https://trusted.app>;
4-
acl:mode acl:Read, acl:Write, acl:Append, acl:Control].
6+
c:me
7+
acl:trustedApp
8+
[ acl:mode acl:Read, acl:Write; acl:origin <https://app.example.com> ].
9+
c0:me
10+
acl:trustedApp
11+
[
12+
acl:mode acl:Append, acl:Control, acl:Read, acl:Write;
13+
acl:origin <https://trusted.app>
14+
].

test/unit/login-request-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,9 @@ describe('LoginRequest', () => {
175175
})
176176

177177
describe('redirectPostLogin()', () => {
178-
it('should redirect to the /authorize url if response_type includes token', () => {
178+
it('should redirect to the /consent url if response_type includes token', () => {
179179
let res = HttpMocks.createResponse()
180-
let authUrl = 'https://localhost:8443/authorize?response_type=token'
180+
let authUrl = 'https://localhost:8443/consent?response_type=token'
181181
let validUser = accountManager.userAccountFrom({ username: 'alice' })
182182

183183
let authQueryParams = {

0 commit comments

Comments
 (0)