Skip to content

Commit

Permalink
v2.2.2-beta.1
Browse files Browse the repository at this point in the history
  • Loading branch information
maxmantz committed Jan 10, 2017
1 parent e604d8a commit 0849090
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 12 deletions.
2 changes: 1 addition & 1 deletion dist/redux-oidc.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "redux-oidc",
"version": "2.2.1",
"version": "2.2.2-beta.1",
"description": "A package for managing OpenID Connect authentication in redux apps",
"main": "dist/redux-oidc.js",
"scripts": {
Expand Down
9 changes: 8 additions & 1 deletion src/OidcProvider.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { PropTypes } from 'react';
import { userExpired, userFound, silentRenewError, sessionTerminated, userExpiring } from './actions';
import { userExpired, userFound, silentRenewError, sessionTerminated, userExpiring, userSignedOut } from './actions';

class OidcProvider extends React.Component {
static propTypes = {
Expand Down Expand Up @@ -29,6 +29,7 @@ class OidcProvider extends React.Component {
this.userManager.events.addAccessTokenExpired(this.onAccessTokenExpired);
this.userManager.events.addAccessTokenExpiring(this.onAccessTokenExpiring);
this.userManager.events.addUserUnloaded(this.onUserUnloaded);
this.userManager.events.addUserSignedOut(this.onUserSignedOut);
}

componentWillUnmount() {
Expand All @@ -38,6 +39,7 @@ class OidcProvider extends React.Component {
this.userManager.events.removeAccessTokenExpired(this.onAccessTokenExpired);
this.userManager.events.removeAccessTokenExpiring(this.onAccessTokenExpiring);
this.userManager.events.removeUserUnloaded(this.onUserUnloaded);
this.userManager.events.removeUserSignedOut(this.onUserSignedOut);
}

// event callback when the user has been loaded (on silent renew or redirect)
Expand Down Expand Up @@ -65,6 +67,11 @@ class OidcProvider extends React.Component {
this.props.store.dispatch(userExpiring());
}

// event callback when the user is signed out
onUserSignedOut = () => {
this.props.store.dispatch(userSignedOut());
}

render() {
return React.Children.only(this.props.children);
}
Expand Down
9 changes: 8 additions & 1 deletion src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {
SILENT_RENEW_ERROR,
USER_EXPIRING,
SESSION_TERMINATED,
LOADING_USER
LOADING_USER,
USER_SIGNED_OUT
} from '../constants'

// dispatched when the existing user expired
Expand Down Expand Up @@ -60,3 +61,9 @@ export function loadingUser() {
type: LOADING_USER
};
}

export function userSignedOut() {
return {
type: USER_SIGNED_OUT
};
}
1 change: 1 addition & 0 deletions src/constants/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export const SESSION_TERMINATED = 'redux-oidc/SESSION_TERMINATED';
export const USER_EXPIRING = 'redux-oidc/USER_EXPIRING';
export const USER_FOUND = 'redux-oidc/USER_FOUND';
export const LOADING_USER = 'redux-oidc/LOADING_USER';
export const USER_SIGNED_OUT = 'redux-oidc/USER_SIGNED_OUT';
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const SILENT_RENEW_ERROR = require('./constants').SILENT_RENEW_ERROR;
export const SESSION_TERMINATED = require('./constants').SESSION_TERMINATED;
export const USER_EXPIRING = require('./constants').USER_EXPIRING;
export const LOADING_USER = require('./constants').LOADING_USER;
export const USER_SIGNED_OUT = require('./constants').USER_SIGNED_OUT;

// actions
export const userExpired = require('./actions').userExpired;
Expand All @@ -26,5 +27,6 @@ export const silentRenewError = require('./actions').silentRenewError;
export const sessionTerminated = require('./actions').sessionTerminated;
export const userExpiring = require('./actions').userExpiring;
export const loadingUser = require('./actions').loadingUser;
export const userSignedOut = require('./actions').userSignedOut;

export default createOidcMiddleware;
4 changes: 3 additions & 1 deletion src/reducer/reducer-immutable.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
USER_NOT_FOUND,
SILENT_RENEW_ERROR,
SESSION_TERMINATED,
LOADING_USER
LOADING_USER,
USER_SIGNED_OUT
} from '../constants';

const initialState = fromJS({
Expand All @@ -21,6 +22,7 @@ export default function reducer(state = initialState, action) {
case SILENT_RENEW_ERROR:
return state.set('isLoadingUser', false);
case SESSION_TERMINATED:
case USER_SIGNED_OUT:
return fromJS({
user: null,
isLoadingUser: false
Expand Down
4 changes: 3 additions & 1 deletion src/reducer/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {
USER_FOUND, USER_NOT_FOUND,
SILENT_RENEW_ERROR,
SESSION_TERMINATED,
LOADING_USER
LOADING_USER,
USER_SIGNED_OUT
} from '../constants';

const initialState = {
Expand All @@ -19,6 +20,7 @@ export default function reducer(state = initialState, action) {
case SILENT_RENEW_ERROR:
return Object.assign({}, { ...state }, { isLoadingUser: false });
case SESSION_TERMINATED:
case USER_SIGNED_OUT:
return Object.assign({}, { ...state }, { user: null, isLoadingUser: false });
case REDIRECT_SUCCESS:
case USER_FOUND:
Expand Down
18 changes: 16 additions & 2 deletions tests/OidcProvider.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import './setup';
import expect from 'expect';
import sinon from 'sinon';
import OidcProvider from '../src/OidcProvider';
import { userExpired, userFound, silentRenewError, sessionTerminated, userExpiring, redirectSuccess } from '../src/actions';
import { userExpired, userFound, silentRenewError, sessionTerminated, userExpiring, redirectSuccess, userSignedOut } from '../src/actions';

describe('<OidcProvider />', () => {
let userManagerMock;
Expand All @@ -13,11 +13,13 @@ describe('<OidcProvider />', () => {
let addAccessTokenExpiredStub;
let addUserUnloadedStub;
let addAccessTokenExpiringStub;
let addUserSignedOutStub;
let removeUserLoadedStub;
let removeSilentRenewErrorStub;
let removeAccessTokenExpiredStub;
let removeUserUnloadedStub;
let removeAccessTokenExpiringStub;
let removeUserSignedOutStub;
let dispatchStub;
let props;
let provider;
Expand All @@ -28,11 +30,13 @@ describe('<OidcProvider />', () => {
addAccessTokenExpiredStub = sinon.stub();
addUserUnloadedStub = sinon.stub();
addAccessTokenExpiringStub = sinon.stub();
addUserSignedOutStub = sinon.stub();
removeUserLoadedStub = sinon.stub();
removeSilentRenewErrorStub = sinon.stub();
removeAccessTokenExpiredStub = sinon.stub();
removeUserUnloadedStub = sinon.stub();
removeAccessTokenExpiringStub = sinon.stub();
removeUserSignedOutStub = sinon.stub();
dispatchStub = sinon.stub();

eventsMock = {
Expand All @@ -41,11 +45,13 @@ describe('<OidcProvider />', () => {
addAccessTokenExpired: addAccessTokenExpiredStub,
addUserUnloaded: addUserUnloadedStub,
addAccessTokenExpiring: addAccessTokenExpiringStub,
addUserSignedOut: addUserSignedOutStub,
removeUserLoaded: removeUserLoadedStub,
removeSilentRenewError: removeSilentRenewErrorStub,
removeAccessTokenExpired: removeAccessTokenExpiredStub,
removeUserUnloaded: removeUserUnloadedStub,
removeAccessTokenExpiring: removeAccessTokenExpiringStub
removeAccessTokenExpiring: removeAccessTokenExpiringStub,
removeUserSignedOut: removeUserSignedOutStub
};

userManagerMock = {
Expand Down Expand Up @@ -82,6 +88,7 @@ describe('<OidcProvider />', () => {
expect(addAccessTokenExpiredStub.calledWith(provider.onAccessTokenExpired)).toEqual(true);
expect(addUserUnloadedStub.calledWith(provider.onUserUnloaded)).toEqual(true);
expect(addAccessTokenExpiringStub.calledWith(provider.onAccessTokenExpiring)).toEqual(true);
expect(addUserSignedOutStub.calledWith(provider.onUserSignedOut)).toEqual(true);
});

it('should remove event registrations on componentWillUnmount()', () => {
Expand All @@ -92,6 +99,7 @@ describe('<OidcProvider />', () => {
expect(removeAccessTokenExpiredStub.calledWith(provider.onAccessTokenExpired)).toEqual(true);
expect(removeUserUnloadedStub.calledWith(provider.onUserUnloaded)).toEqual(true);
expect(removeAccessTokenExpiringStub.calledWith(provider.onAccessTokenExpiring)).toEqual(true);
expect(removeUserSignedOutStub.calledWith(provider.onUserSignedOut)).toEqual(true);
});

it('should handle the userLoaded event correctly', () => {
Expand Down Expand Up @@ -125,4 +133,10 @@ describe('<OidcProvider />', () => {

expect(dispatchStub.calledWith(userExpiring())).toEqual(true);
});

it('should handle the userSignedOut event correctly', () => {
provider.onUserSignedOut();

expect(dispatchStub.calledWith(userSignedOut())).toEqual(true);
});
});
11 changes: 9 additions & 2 deletions tests/actions/index.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import '../setup';
import expect from 'expect';
import sinon from 'sinon';
import { USER_EXPIRED, REDIRECT_SUCCESS, USER_FOUND, SILENT_RENEW_ERROR, USER_EXPIRING, SESSION_TERMINATED, LOADING_USER } from '../../src/constants';
import { userExpired, userFound, silentRenewError, sessionTerminated, userExpiring, redirectSuccess, loadingUser } from '../../src/actions';
import { USER_EXPIRED, REDIRECT_SUCCESS, USER_FOUND, SILENT_RENEW_ERROR, USER_EXPIRING, SESSION_TERMINATED, LOADING_USER, USER_SIGNED_OUT } from '../../src/constants';
import { userExpired, userFound, silentRenewError, sessionTerminated, userExpiring, redirectSuccess, loadingUser, userSignedOut } from '../../src/actions';

describe('action - userExpired', () => {
it('should return the correct action object', () => {
Expand Down Expand Up @@ -61,3 +61,10 @@ describe('action - loadingUser', () => {
expect(action.type).toEqual(LOADING_USER);
});
});

describe('action - userSignedOut', () => {
it('should return the correct action object', () => {
const action = userSignedOut();
expect(action.type).toEqual(USER_SIGNED_OUT);
});
});
11 changes: 10 additions & 1 deletion tests/reducer/reducer-immutable.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import '../setup';
import expect from 'expect';
import sinon from 'sinon';
import { fromJS } from 'immutable';
import { userExpired, userFound, userNotFound, silentRenewError, sessionTerminated, userExpiring, redirectSuccess, loadingUser } from '../../src/actions';
import { userExpired, userFound, userNotFound, silentRenewError, sessionTerminated, userExpiring, redirectSuccess, loadingUser, userSignedOut } from '../../src/actions';
import reducer from '../../src/reducer/reducer-immutable';

const initialState = fromJS({
Expand Down Expand Up @@ -72,6 +72,15 @@ describe('immutable reducer', () => {
expect(reducer(initialState, loadingUser())).toEqual(expectedResult);
});

it('should handle USER_SIGNED_OUT correctly', () => {
const expectedResult = fromJS({
user: null,
isLoadingUser: false
});

expect(reducer(initialState, userSignedOut())).toEqual(expectedResult);
});

it('should handle the default correctly', () => {
const expectedResult = fromJS({
some: 'data'
Expand Down
12 changes: 11 additions & 1 deletion tests/reducer/reducer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {
sessionTerminated,
userExpiring,
redirectSuccess,
loadingUser
loadingUser,
userSignedOut
} from '../../src/actions';
import reducer from '../../src/reducer/reducer';

Expand Down Expand Up @@ -79,6 +80,15 @@ describe('reducer', () => {
expect(reducer(initialState, loadingUser())).toEqual(expectedResult);
});

it('should handle USER_SIGNED_OUT correctly', () => {
const expectedResult = {
user: null,
isLoadingUser: false
};

expect(reducer(initialState, userSignedOut())).toEqual(expectedResult);
});

it('should handle the default correctly', () => {
const expectedResult = {
some: 'data'
Expand Down

0 comments on commit 0849090

Please sign in to comment.