mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
Merge pull request #1151 from gradido/catch-verify-login
fix: Catch Expired Session when Coming from Admin Interface
This commit is contained in:
commit
d5867a4a8c
2
.github/workflows/test.yml
vendored
2
.github/workflows/test.yml
vendored
@ -399,7 +399,7 @@ jobs:
|
||||
report_name: Coverage Frontend
|
||||
type: lcov
|
||||
result_path: ./coverage/lcov.info
|
||||
min_coverage: 86
|
||||
min_coverage: 87
|
||||
token: ${{ github.token }}
|
||||
|
||||
##############################################################################
|
||||
|
||||
@ -15,12 +15,19 @@ const addNavigationGuards = (router, store, apollo) => {
|
||||
router.beforeEach(async (to, from, next) => {
|
||||
if (to.path === '/authenticate' && to.query.token) {
|
||||
store.commit('token', to.query.token)
|
||||
const result = await apollo.query({
|
||||
query: verifyLogin,
|
||||
fetchPolicy: 'network-only',
|
||||
})
|
||||
store.dispatch('login', result.data.verifyLogin)
|
||||
next({ path: '/overview' })
|
||||
await apollo
|
||||
.query({
|
||||
query: verifyLogin,
|
||||
fetchPolicy: 'network-only',
|
||||
})
|
||||
.then((result) => {
|
||||
store.dispatch('login', result.data.verifyLogin)
|
||||
next({ path: '/overview' })
|
||||
})
|
||||
.catch(() => {
|
||||
store.dispatch('logout')
|
||||
next()
|
||||
})
|
||||
} else {
|
||||
next()
|
||||
}
|
||||
|
||||
@ -2,15 +2,28 @@ import addNavigationGuards from './guards'
|
||||
import router from './router'
|
||||
|
||||
const storeCommitMock = jest.fn()
|
||||
const storeDispatchMock = jest.fn()
|
||||
const apolloQueryMock = jest.fn().mockResolvedValue({
|
||||
data: {
|
||||
verifyLogin: {
|
||||
firstName: 'Peter',
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
const store = {
|
||||
commit: storeCommitMock,
|
||||
state: {
|
||||
token: null,
|
||||
},
|
||||
dispatch: storeDispatchMock,
|
||||
}
|
||||
|
||||
addNavigationGuards(router, store)
|
||||
const apollo = {
|
||||
query: apolloQueryMock,
|
||||
}
|
||||
|
||||
addNavigationGuards(router, store, apollo)
|
||||
|
||||
describe('navigation guards', () => {
|
||||
beforeEach(() => {
|
||||
@ -29,6 +42,46 @@ describe('navigation guards', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('authenticate', () => {
|
||||
const navGuard = router.beforeHooks[1]
|
||||
const next = jest.fn()
|
||||
|
||||
describe('with valid token', () => {
|
||||
beforeEach(() => {
|
||||
navGuard({ path: '/authenticate', query: { token: 'valid-token' } }, {}, next)
|
||||
})
|
||||
|
||||
it('commts the token to the store', () => {
|
||||
expect(storeCommitMock).toBeCalledWith('token', 'valid-token')
|
||||
})
|
||||
|
||||
it('calls verifyLogin', () => {
|
||||
expect(apolloQueryMock).toBeCalled()
|
||||
})
|
||||
|
||||
it('commits login to the store', () => {
|
||||
expect(storeDispatchMock).toBeCalledWith('login', { firstName: 'Peter' })
|
||||
})
|
||||
})
|
||||
|
||||
describe('with valid token and server error', () => {
|
||||
beforeEach(() => {
|
||||
apolloQueryMock.mockRejectedValue({
|
||||
message: 'Ouch!',
|
||||
})
|
||||
navGuard({ path: '/authenticate', query: { token: 'valid-token' } }, {}, next)
|
||||
})
|
||||
|
||||
it('dispatches logout to store', () => {
|
||||
expect(storeDispatchMock).toBeCalledWith('logout')
|
||||
})
|
||||
|
||||
it('calls next', () => {
|
||||
expect(next).toBeCalledWith()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('authorization', () => {
|
||||
const navGuard = router.beforeHooks[2]
|
||||
const next = jest.fn()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user