-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'refs/heads/develop' into gr-DCJ-163-auth-design-overview
- Loading branch information
Showing
36 changed files
with
892 additions
and
634 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# builder image | ||
FROM node:22.7.0 AS builder | ||
FROM node:22.8.0 AS builder | ||
LABEL maintainer="[email protected]" | ||
|
||
# set working directory | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* eslint-disable no-undef */ | ||
|
||
import {OidcBroker} from '../../../src/libs/auth/oidcBroker'; | ||
import {Auth} from '../../../src/libs/auth/auth'; | ||
import {OAuth2} from '../../../src/libs/ajax/OAuth2'; | ||
import {Storage} from '../../../src/libs/storage'; | ||
import {v4 as uuid} from 'uuid'; | ||
import {mockOidcUser} from './mockOidcUser'; | ||
|
||
describe('Auth Failure', function () { | ||
it('Sign In error throws expected message', async function () { | ||
cy.stub(OidcBroker, 'signIn').returns(null); | ||
cy.on('fail', (err) => { | ||
return err.message !== Auth.signInError(); | ||
}); | ||
Auth.signIn().then(() => { | ||
expect(Storage.getOidcUser()).to.be.null; | ||
expect(Storage.userIsLogged()).to.be.false; | ||
}); | ||
}); | ||
}); | ||
|
||
describe('Auth Success', function () { | ||
// Intercept configuration calls | ||
beforeEach(() => { | ||
cy.intercept({ | ||
method: 'GET', | ||
url: '/config.json', | ||
hostname: 'localhost', | ||
}, {'env': 'ci'}); | ||
cy.stub(OAuth2, 'getConfig').returns({ | ||
'authorityEndpoint': Cypress.config().baseUrl, | ||
'clientId': 'clientId' | ||
}); | ||
Auth.initialize(); | ||
}); | ||
|
||
it('Sign In stores the current user', async function () { | ||
cy.stub(OidcBroker, 'signIn').returns(mockOidcUser); | ||
await Auth.signIn(); | ||
expect(Storage.getOidcUser()).to.not.be.empty; | ||
expect(Storage.userIsLogged()).to.be.true; | ||
}); | ||
|
||
it('Sign Out Clears the session when called', async function () { | ||
Storage.setUserIsLogged(true); | ||
Storage.setAnonymousId(uuid()); | ||
Storage.setData('key', 'val'); | ||
Storage.setEnv('test'); | ||
expect(Storage.userIsLogged()).to.be.true; | ||
expect(Storage.getAnonymousId()).to.not.be.empty; | ||
expect(Storage.getData('key')).to.not.be.empty; | ||
expect(Storage.getEnv()).to.not.be.empty; | ||
await Auth.signOut(); | ||
expect(Storage.userIsLogged()).to.be.false; | ||
expect(Storage.getAnonymousId()).to.be.null; | ||
expect(Storage.getData('key')).to.be.null; | ||
expect(Storage.getEnv()).to.be.null; | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import {OidcUser} from "../../../src/libs/auth/oidcBroker"; | ||
|
||
export const mockOidcUser: OidcUser = { | ||
access_token: '', | ||
get expires_in(): number | undefined { | ||
return undefined; | ||
}, | ||
session_state: undefined, | ||
state: undefined, | ||
token_type: '', | ||
get expired(): boolean | undefined { | ||
return undefined; | ||
}, | ||
get scopes(): string[] { | ||
return []; | ||
}, | ||
toStorageString(): string { | ||
return ''; | ||
}, | ||
profile: { | ||
jti: undefined, | ||
nbf: undefined, | ||
sub: undefined, | ||
iss: '', | ||
aud: '', | ||
exp: 0, | ||
iat: 0 | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* eslint-disable no-undef */ | ||
|
||
import {OAuth2} from '../../../src/libs/ajax/OAuth2'; | ||
import {OidcBroker} from '../../../src/libs/auth/oidcBroker'; | ||
|
||
describe('OidcBroker Failure', function () { | ||
|
||
it('Get User Manager Fails without initialization', function () { | ||
cy.on('fail', (err) => { | ||
return !err.message.includes('initialized'); | ||
}); | ||
OidcBroker.getUserManager(); | ||
}); | ||
|
||
it('Get User Manager Settings Fails without initialization', function () { | ||
cy.on('fail', (err) => { | ||
return !err.message.includes('initialized'); | ||
}); | ||
OidcBroker.getUserManagerSettings(); | ||
}); | ||
|
||
}); | ||
|
||
describe('OidcBroker Success', function () { | ||
// Intercept configuration calls | ||
beforeEach(() => { | ||
cy.intercept({ | ||
method: 'GET', | ||
url: '/config.json', | ||
hostname: 'localhost', | ||
}, {'env': 'ci'}); | ||
cy.stub(OAuth2, 'getConfig').returns({ | ||
'authorityEndpoint': Cypress.config().baseUrl, | ||
'clientId': 'clientId' | ||
}); | ||
}); | ||
|
||
it('Initialization Succeeds', async function () { | ||
await OidcBroker.initialize(); | ||
expect(OidcBroker.getUserManager()).to.not.be.null; | ||
expect(OidcBroker.getUserManagerSettings()).to.not.be.null; | ||
}); | ||
|
||
it('Sign In calls Oidc Broker UserManager sign-in popup function', async function () { | ||
await OidcBroker.initialize(); | ||
const um = OidcBroker.getUserManager(); | ||
cy.spy(um, 'signinPopup').as('signinPopup'); | ||
// Since we are not calling a real sign-in url, we expect oidc-client errors when doing so | ||
cy.on('uncaught:exception', (err) => { | ||
return !(err.message.includes('Invalid URL')) | ||
}); | ||
OidcBroker.signIn(); | ||
expect(um.signinPopup).to.be.called; | ||
}); | ||
|
||
it('Sign Out calls Oidc UserManager sign-out functions', async function () { | ||
await OidcBroker.initialize(); | ||
const um = OidcBroker.getUserManager(); | ||
cy.spy(um, 'removeUser').as('removeUser'); | ||
cy.spy(um, 'clearStaleState').as('clearStaleState'); | ||
await OidcBroker.signOut(); | ||
expect(um.removeUser).to.be.called; | ||
expect(um.clearStaleState).to.be.called; | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.