-
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.
- Loading branch information
Showing
18 changed files
with
323 additions
and
317 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
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
This file was deleted.
Oops, something went wrong.
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,30 +1,113 @@ | ||
/* eslint-disable no-undef */ | ||
|
||
import React from 'react'; | ||
import { mount } from 'cypress/react'; | ||
import {mount} from 'cypress/react18'; | ||
import SignInButton from '../../../src/components/SignInButton'; | ||
import { Config } from '../../../src/libs/config'; | ||
import {User} from '../../../src/libs/ajax/User'; | ||
import {Auth} from '../../../src/libs/auth/auth'; | ||
import {Storage} from '../../../src/libs/storage'; | ||
import {Metrics} from '../../../src/libs/ajax/Metrics'; | ||
import {StackdriverReporter} from '../../../src/libs/stackdriverReporter'; | ||
import {ToS} from '../../../src/libs/ajax/ToS'; | ||
import {mockOidcUser} from '../Auth/mockOidcUser'; | ||
|
||
const signInText = 'Sign-in'; | ||
const signInText = 'Sign In'; | ||
|
||
// Note that we do not want to click the signin button | ||
// in tests as that would trigger an auth-flow we cannot | ||
// replicate in a test environment. | ||
describe('Sign In Component', function() { | ||
it('Sign In Button Loads when client id is valid', function () { | ||
const duosUser = { | ||
displayName: 'display name', | ||
email: '[email protected]', | ||
roles: [{ | ||
name: 'Admin' | ||
}] | ||
}; | ||
|
||
const userStatus = { | ||
'adminEnabled': true, | ||
'enabled': true, | ||
'inAllUsersGroup': true, | ||
'inGoogleProxyGroup': true, | ||
'tosAccepted': true | ||
}; | ||
|
||
const notAcceptedUserStatus = Object.assign({}, userStatus, {'tosAccepted': false}); | ||
|
||
describe('Sign In: Component Loads', function () { | ||
|
||
it('Sign In Button Loads', function () { | ||
cy.viewport(600, 300); | ||
mount(<SignInButton history={undefined}/>); | ||
cy.contains(signInText).should('exist'); | ||
}); | ||
|
||
it('Sign In: On Success', function () { | ||
cy.viewport(600, 300); | ||
cy.stub(Auth, 'signIn').returns(Promise.resolve(mockOidcUser)); | ||
cy.stub(User, 'getMe').returns(duosUser); | ||
cy.stub(StackdriverReporter, 'report'); | ||
cy.stub(Metrics, 'identify'); | ||
cy.stub(Metrics, 'syncProfile'); | ||
cy.stub(Metrics, 'captureEvent'); | ||
cy.stub(ToS, 'getStatus').returns(userStatus); | ||
mount(<SignInButton history={[]}/>); | ||
cy.get('button').click().then(() => { | ||
expect(Storage.getCurrentUser()).to.deep.equal(duosUser); | ||
expect(Storage.getAnonymousId()).to.not.be.null; | ||
expect(StackdriverReporter.report).to.not.be.called; | ||
expect(Metrics.identify).to.be.called; | ||
expect(Metrics.syncProfile).to.be.called; | ||
expect(Metrics.captureEvent).to.be.called; | ||
}); | ||
}); | ||
|
||
it('Sign In: No Roles Error Reporter Is Called', function () { | ||
const bareUser = {email: '[email protected]'}; | ||
cy.viewport(600, 300); | ||
// Load the client id from perf so we can have a valid button | ||
cy.readFile('config/alpha.json').then((config) => { | ||
const clientId = config.clientId; | ||
cy.stub(Config, 'getGoogleClientId').returns(clientId); | ||
mount(<SignInButton />); | ||
cy.contains(signInText).should('exist'); | ||
cy.stub(Auth, 'signIn').returns(Promise.resolve(mockOidcUser)); | ||
cy.stub(User, 'getMe').returns(bareUser); | ||
cy.stub(StackdriverReporter, 'report'); | ||
cy.stub(Metrics, 'identify'); | ||
cy.stub(Metrics, 'syncProfile'); | ||
cy.stub(Metrics, 'captureEvent'); | ||
cy.stub(ToS, 'getStatus').returns(userStatus); | ||
mount(<SignInButton history={[]}/>); | ||
cy.get('button').click().then(() => { | ||
expect(StackdriverReporter.report).to.be.called; | ||
}); | ||
}); | ||
it('Spinner loads when client id is empty', function () { | ||
|
||
it('Sign In: Redirects to ToS if not accepted', function () { | ||
cy.viewport(600, 300); | ||
cy.stub(Config, 'getGoogleClientId').returns(''); | ||
mount(<SignInButton />); | ||
cy.contains(signInText).should('not.exist'); | ||
cy.stub(Auth, 'signIn').returns(Promise.resolve(mockOidcUser)); | ||
cy.stub(User, 'getMe').returns(duosUser); | ||
cy.stub(ToS, 'getStatus').returns(notAcceptedUserStatus); | ||
cy.stub(Metrics, 'identify'); | ||
cy.stub(Metrics, 'syncProfile'); | ||
cy.stub(Metrics, 'captureEvent'); | ||
let history = []; | ||
mount(<SignInButton history={history}/>); | ||
cy.get('button').click().then(() => { | ||
expect(history).to.not.be.empty; | ||
expect(history[0].includes('tos_acceptance')).to.be.true; | ||
}); | ||
}); | ||
|
||
it('Sign In: Registers user if not found and redirects to ToS', function () { | ||
cy.viewport(600, 300); | ||
cy.stub(Auth, 'signIn').returns(Promise.resolve(mockOidcUser)); | ||
// Simulate user not found | ||
cy.stub(User, 'getMe').throws(); | ||
cy.stub(User, 'registerUser').returns(duosUser); | ||
cy.stub(ToS, 'getStatus').returns(notAcceptedUserStatus); | ||
cy.stub(Metrics, 'identify'); | ||
cy.stub(Metrics, 'syncProfile'); | ||
cy.stub(Metrics, 'captureEvent'); | ||
let history = []; | ||
mount(<SignInButton history={history}/>); | ||
cy.get('button').click().then(() => { | ||
expect(User.registerUser).to.be.called; | ||
expect(history).to.not.be.empty; | ||
expect(history[0].includes('tos_acceptance')).to.be.true; | ||
}); | ||
}); | ||
|
||
}); |
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
Oops, something went wrong.