Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise mirage timing sso test #1404

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
*.swp
*.swo
node_modules
.vscode/
!test/webpack/node_modules/@folio/app2/node_modules/
!test/webpack/node_modules/
npm-debug.log
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* Opt-in: handle access-control via cookies. Refs STCOR-671.
* Opt-in: disable login when cookies are disabled. Refs STCOR-762.
* Add arial-label for `ProfileDropdown.js`. Refs STCOR-753.
* Avoid calling `map` on `undefined` via optional-chaining. Refs STCOR-793.

## [10.0.0](https://github.com/folio-org/stripes-core/tree/v10.0.0) (2023-10-11)
[Full Changelog](https://github.com/folio-org/stripes-core/compare/v9.0.0...v10.0.0)
Expand Down
4 changes: 2 additions & 2 deletions src/components/SSOLanding.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ const SSOLanding = () => {

if (!token) {
return (
<div data-test-sso-error>
<div data-test-sso-error id="sso-landing">
No <code>ssoToken</code> cookie or query parameter
</div>
);
}

return (
<div data-test-sso-success>
<div data-test-sso-success id="sso-landing">
<p>
Logged in with token <tt>{token}</tt> from {getParams()?.ssoToken ? 'param' : 'cookie'}.
</p>
Expand Down
8 changes: 5 additions & 3 deletions src/loginServices.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,9 +397,11 @@ export function spreadUserWithPerms(userWithPerms) {
...userWithPerms?.user?.personal,
};

// remap data's array of permission-names to set with
// permission-names for keys and `true` for values
const perms = Object.assign({}, ...userWithPerms?.permissions?.permissions.map(p => ({ [p.permissionName]: true })));
// remap permissions from [foo, bar, bat] to { foo: true, bar: true, ... }
const perms = userWithPerms?.permissions?.permissions?.reduce((acc, i) => {
acc[i.permissionName] = true;
return acc;
}, {});

return { user, perms };
}
Expand Down
31 changes: 31 additions & 0 deletions test/bigtest/network/scenarios/userWithPerms.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
export default (server) => {
server.get('/bl-users/_self', {
'user': {
'username': 'diku_admin',
'id': '882c886a-2d9a-5ffa-afc5-13912c257b99',
'active': true,
'patronGroup': '3684a786-6671-4268-8ed0-9db82ebca60b',
'proxyFor': [
],
'personal': {
'lastName': 'ADMINISTRATOR',
'firstName': 'DIKU',
'email': '[email protected]',
'addresses': [
]
},
'createdDate': '2024-01-22T01:55:50.661+00:00',
'updatedDate': '2024-01-22T01:55:50.661+00:00',
'metadata': {
'createdDate': '2024-01-22T01:52:08.076+00:00',
'updatedDate': '2024-01-22T01:55:50.656+00:00',
'updatedByUserId': '882c886a-2d9a-5ffa-afc5-13912c257b99'
},
'departments': [
]
},
'permissions': {
'permissions': ['configuration.entries.collection.get']
}
});
};
39 changes: 24 additions & 15 deletions test/bigtest/tests/sso-login-test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from 'react';
import { expect } from 'chai';
import { beforeEach, it, describe } from '@bigtest/mocha';

import { beforeEach, afterEach, it, describe } from '@bigtest/mocha';
import localforage from 'localforage';
import setupApplication from '../helpers/setup-core-application';
import SSOLandingInteractor from '../interactors/SSOLanding';

Expand All @@ -18,49 +17,59 @@ describe('Login via SSO', () => {
describe('SSO redirect', () => {
const sso = new SSOLandingInteractor();

describe('Renders error without token', () => {
describe('Reads token in params', () => {
setupApplication({
scenarios: ['userWithPerms'],
disableAuth: false,
});

beforeEach(async function () {
this.visit('/sso-landing');
this.visit('/sso-landing?ssoToken=c0ffee');
});

it('Shows error message', () => {
expect(sso.isError).to.be.true;
afterEach(async () => {
await localforage.clear();
});

it('Does not show token message', () => {
expect(sso.isValid).to.be.false;
it('Shows token message', () => {
expect(sso.isValid).to.be.true;
});
});

describe('Reads token in params', () => {
describe('Reads token in cookie', () => {
setupApplication({
disableAuth: false,
cookies: { ssoToken: 'c0ffee-c0ffee' },
});

beforeEach(async function () {
this.visit('/sso-landing?ssoToken=c0ffee');
this.visit('/sso-landing');
});

afterEach(async () => {
await localforage.clear();
});

it('Shows token message', () => {
expect(sso.isValid).to.be.true;
});
});

describe('Reads token in cookie', () => {
describe('Renders error without token', () => {
setupApplication({
disableAuth: false,
cookies: { ssoToken: 'c0ffee-c0ffee' },
});

beforeEach(async function () {
this.visit('/sso-landing');
});

it('Shows token message', () => {
expect(sso.isValid).to.be.true;
it('Shows error message', () => {
expect(sso.isError).to.be.true;
});

it('Does not show token message', () => {
expect(sso.isValid).to.be.false;
});
});
});
Expand Down
Loading