From 0849090ff1c7dfcb8d7f2e39e2c6063f09aba0d2 Mon Sep 17 00:00:00 2001 From: Maximilian Mantz Date: Tue, 10 Jan 2017 19:20:02 +0100 Subject: [PATCH] v2.2.2-beta.1 --- dist/redux-oidc.js | 2 +- package.json | 2 +- src/OidcProvider.js | 9 ++++++++- src/actions/index.js | 9 ++++++++- src/constants/index.js | 1 + src/index.js | 2 ++ src/reducer/reducer-immutable.js | 4 +++- src/reducer/reducer.js | 4 +++- tests/OidcProvider.test.js | 18 ++++++++++++++++-- tests/actions/index.test.js | 11 +++++++++-- tests/reducer/reducer-immutable.test.js | 11 ++++++++++- tests/reducer/reducer.test.js | 12 +++++++++++- 12 files changed, 73 insertions(+), 12 deletions(-) diff --git a/dist/redux-oidc.js b/dist/redux-oidc.js index 16df98c..41aa0d4 100644 --- a/dist/redux-oidc.js +++ b/dist/redux-oidc.js @@ -1 +1 @@ -!function(e,r){if("object"==typeof exports&&"object"==typeof module)module.exports=r(require("react"),require("immutable"),require("oidc-client"));else if("function"==typeof define&&define.amd)define(["react","immutable","oidc-client"],r);else{var t="object"==typeof exports?r(require("react"),require("immutable"),require("oidc-client")):r(e.react,e.immutable,e["oidc-client"]);for(var n in t)("object"==typeof exports?exports:e)[n]=t[n]}}(this,function(e,r,t){return function(e){function r(n){if(t[n])return t[n].exports;var o=t[n]={exports:{},id:n,loaded:!1};return e[n].call(o.exports,o,o.exports,r),o.loaded=!0,o.exports}var t={};return r.m=e,r.c=t,r.p="",r(0)}([function(e,r,t){e.exports=t(8)},function(e,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.STORAGE_KEY="oidc.expired",r.USER_EXPIRED="redux-oidc/USER_EXPIRED",r.REDIRECT_SUCCESS="redux-oidc/REDIRECT_SUCCESS",r.USER_LOADED="redux-oidc/USER_LOADED",r.SILENT_RENEW_ERROR="redux-oidc/SILENT_RENEW_ERROR",r.SESSION_TERMINATED="redux-oidc/SESSION_TERMINATED",r.USER_EXPIRING="redux-oidc/USER_EXPIRING",r.USER_FOUND="redux-oidc/USER_FOUND",r.LOADING_USER="redux-oidc/LOADING_USER"},function(e,r,t){"use strict";function n(){return{type:l.USER_EXPIRED}}function o(e){return{type:l.REDIRECT_SUCCESS,payload:e}}function i(e){return{type:l.USER_FOUND,payload:e}}function s(e){return{type:l.SILENT_RENEW_ERROR,payload:e}}function u(){return{type:l.SESSION_TERMINATED}}function a(){return{type:l.USER_EXPIRING}}function c(){return{type:l.LOADING_USER}}Object.defineProperty(r,"__esModule",{value:!0}),r.userExpired=n,r.redirectSuccess=o,r.userFound=i,r.silentRenewError=s,r.sessionTerminated=u,r.userExpiring=a,r.loadingUser=c;var l=t(1)},function(e,r,t){"use strict";function n(e){return new o.UserManager(e)}Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=n;var o=t(13)},function(e,r){e.exports=require("react")},function(e,r,t){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}function o(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}function i(e,r){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!r||"object"!=typeof r&&"function"!=typeof r?e:r}function s(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function, not "+typeof r);e.prototype=Object.create(r&&r.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),r&&(Object.setPrototypeOf?Object.setPrototypeOf(e,r):e.__proto__=r)}Object.defineProperty(r,"__esModule",{value:!0});var u=function(){function e(e,r){for(var t=0;t3&&void 0!==arguments[3]?arguments[3]:"/callback";if(!e||!e.getUser||!e.signinRedirect)throw new Error("You must provide a user manager!");if("string"!=typeof n)throw new Error("You must provide the callback route!");if(r&&"function"==typeof r||(r=function(e,r){return!0}),localStorage.getItem(a.STORAGE_KEY)&&window.location.pathname.indexOf(n)===-1){localStorage.removeItem(a.STORAGE_KEY);for(var o in localStorage)o.indexOf("oidc")!==-1&&o.indexOf("oidc.user")===-1&&localStorage.removeItem(o)}return function(n){return function(o){return function(u){return!r(n.getState(),u)||localStorage.getItem(a.STORAGE_KEY)?o(u):l&&!l.expired?o(u):(o((0,c.loadingUser)()),localStorage.setItem(a.STORAGE_KEY,!0),void e.getUser().then(function(r){return i(o,e,r,t,u)})["catch"](s))}}}}Object.defineProperty(r,"__esModule",{value:!0}),r.storedUser=void 0,r.setStoredUser=n,r.removeStoredUser=o,r.getUserSuccessCallback=i,r.getUserErrorCallback=s,r["default"]=u;var a=t(1),c=t(2),l=r.storedUser=null},function(e,r,t){"use strict";function n(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:s,r=arguments[1];switch(r.type){case i.USER_EXPIRED:return e.set("isLoadingUser",!1);case i.SILENT_RENEW_ERROR:return e.set("isLoadingUser",!1);case i.SESSION_TERMINATED:return(0,o.fromJS)({user:null,isLoadingUser:!1});case i.REDIRECT_SUCCESS:case i.USER_FOUND:return(0,o.fromJS)({user:r.payload,isLoadingUser:!1});case i.LOADING_USER:return e.set("isLoadingUser",!0);default:return e}}Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=n;var o=t(12),i=t(1),s=(0,o.fromJS)({user:null,isLoadingUser:!1})},function(e,r,t){"use strict";function n(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:s,r=arguments[1];switch(r.type){case i.USER_EXPIRED:return Object.assign({},o({},e),{isLoadingUser:!1});case i.SILENT_RENEW_ERROR:return Object.assign({},o({},e),{isLoadingUser:!1});case i.SESSION_TERMINATED:return Object.assign({},o({},e),{user:null,isLoadingUser:!1});case i.REDIRECT_SUCCESS:case i.USER_FOUND:return Object.assign({},o({},e),{user:r.payload,isLoadingUser:!1});case i.LOADING_USER:return Object.assign({},o({},e),{isLoadingUser:!0});default:return e}}Object.defineProperty(r,"__esModule",{value:!0});var o=Object.assign||function(e){for(var r=1;r { + this.props.store.dispatch(userSignedOut()); + } + render() { return React.Children.only(this.props.children); } diff --git a/src/actions/index.js b/src/actions/index.js index d2f01df..b1ab5a1 100644 --- a/src/actions/index.js +++ b/src/actions/index.js @@ -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 @@ -60,3 +61,9 @@ export function loadingUser() { type: LOADING_USER }; } + +export function userSignedOut() { + return { + type: USER_SIGNED_OUT + }; +} diff --git a/src/constants/index.js b/src/constants/index.js index b04adcc..9c6c775 100644 --- a/src/constants/index.js +++ b/src/constants/index.js @@ -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'; diff --git a/src/index.js b/src/index.js index 0e4bb7d..97d3c7e 100644 --- a/src/index.js +++ b/src/index.js @@ -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; @@ -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; diff --git a/src/reducer/reducer-immutable.js b/src/reducer/reducer-immutable.js index b9add64..848f76d 100644 --- a/src/reducer/reducer-immutable.js +++ b/src/reducer/reducer-immutable.js @@ -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({ @@ -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 diff --git a/src/reducer/reducer.js b/src/reducer/reducer.js index c9077b4..c2f2cd1 100644 --- a/src/reducer/reducer.js +++ b/src/reducer/reducer.js @@ -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 = { @@ -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: diff --git a/tests/OidcProvider.test.js b/tests/OidcProvider.test.js index 1fd0464..83fbf72 100644 --- a/tests/OidcProvider.test.js +++ b/tests/OidcProvider.test.js @@ -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('', () => { let userManagerMock; @@ -13,11 +13,13 @@ describe('', () => { 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; @@ -28,11 +30,13 @@ describe('', () => { 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 = { @@ -41,11 +45,13 @@ describe('', () => { addAccessTokenExpired: addAccessTokenExpiredStub, addUserUnloaded: addUserUnloadedStub, addAccessTokenExpiring: addAccessTokenExpiringStub, + addUserSignedOut: addUserSignedOutStub, removeUserLoaded: removeUserLoadedStub, removeSilentRenewError: removeSilentRenewErrorStub, removeAccessTokenExpired: removeAccessTokenExpiredStub, removeUserUnloaded: removeUserUnloadedStub, - removeAccessTokenExpiring: removeAccessTokenExpiringStub + removeAccessTokenExpiring: removeAccessTokenExpiringStub, + removeUserSignedOut: removeUserSignedOutStub }; userManagerMock = { @@ -82,6 +88,7 @@ describe('', () => { 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()', () => { @@ -92,6 +99,7 @@ describe('', () => { 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', () => { @@ -125,4 +133,10 @@ describe('', () => { expect(dispatchStub.calledWith(userExpiring())).toEqual(true); }); + + it('should handle the userSignedOut event correctly', () => { + provider.onUserSignedOut(); + + expect(dispatchStub.calledWith(userSignedOut())).toEqual(true); + }); }); diff --git a/tests/actions/index.test.js b/tests/actions/index.test.js index 76099ef..c338f30 100644 --- a/tests/actions/index.test.js +++ b/tests/actions/index.test.js @@ -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', () => { @@ -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); + }); +}); diff --git a/tests/reducer/reducer-immutable.test.js b/tests/reducer/reducer-immutable.test.js index add3275..015819a 100644 --- a/tests/reducer/reducer-immutable.test.js +++ b/tests/reducer/reducer-immutable.test.js @@ -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({ @@ -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' diff --git a/tests/reducer/reducer.test.js b/tests/reducer/reducer.test.js index d864956..ac4ba2b 100644 --- a/tests/reducer/reducer.test.js +++ b/tests/reducer/reducer.test.js @@ -9,7 +9,8 @@ import { sessionTerminated, userExpiring, redirectSuccess, - loadingUser + loadingUser, + userSignedOut } from '../../src/actions'; import reducer from '../../src/reducer/reducer'; @@ -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'