Resolve "Use cookies instead of local storage for auth in Web UI"
This commit is contained in:
parent
c0055b3b20
commit
c395076fce
18 changed files with 203 additions and 153 deletions
|
|
@ -37,54 +37,21 @@ describe('store/auth', () => {
|
|||
it('authenticated false', () => {
|
||||
const state = {
|
||||
username: 'dummy',
|
||||
token: 'dummy',
|
||||
tokenData: 'dummy',
|
||||
profile: 'dummy',
|
||||
availablePermissions: 'dummy'
|
||||
}
|
||||
store.mutations.authenticated(state, false)
|
||||
expect(state.authenticated).to.equal(false)
|
||||
expect(state.username).to.equal(null)
|
||||
expect(state.token).to.equal(null)
|
||||
expect(state.tokenData).to.equal(null)
|
||||
expect(state.profile).to.equal(null)
|
||||
expect(state.availablePermissions).to.deep.equal({})
|
||||
})
|
||||
it('token null', () => {
|
||||
const state = {}
|
||||
store.mutations.token(state, null)
|
||||
expect(state.token).to.equal(null)
|
||||
expect(state.tokenData).to.deep.equal({})
|
||||
})
|
||||
it('token real', () => {
|
||||
// generated on http://kjur.github.io/jsjws/tool_jwt.html
|
||||
const state = {}
|
||||
let token = 'eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.eyJpc3MiOiJodHRwczovL2p3dC1pZHAuZXhhbXBsZS5jb20iLCJzdWIiOiJtYWlsdG86bWlrZUBleGFtcGxlLmNvbSIsIm5iZiI6MTUxNTUzMzQyOSwiZXhwIjoxNTE1NTM3MDI5LCJpYXQiOjE1MTU1MzM0MjksImp0aSI6ImlkMTIzNDU2IiwidHlwIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9yZWdpc3RlciJ9.'
|
||||
let tokenData = {
|
||||
iss: 'https://jwt-idp.example.com',
|
||||
sub: 'mailto:mike@example.com',
|
||||
nbf: 1515533429,
|
||||
exp: 1515537029,
|
||||
iat: 1515533429,
|
||||
jti: 'id123456',
|
||||
typ: 'https://example.com/register'
|
||||
}
|
||||
store.mutations.token(state, token)
|
||||
expect(state.token).to.equal(token)
|
||||
expect(state.tokenData).to.deep.equal(tokenData)
|
||||
})
|
||||
it('permissions', () => {
|
||||
const state = { availablePermissions: {} }
|
||||
store.mutations.permission(state, {key: 'admin', status: true})
|
||||
expect(state.availablePermissions).to.deep.equal({admin: true})
|
||||
})
|
||||
})
|
||||
describe('getters', () => {
|
||||
it('header', () => {
|
||||
const state = { token: 'helloworld' }
|
||||
expect(store.getters['header'](state)).to.equal('JWT helloworld')
|
||||
})
|
||||
})
|
||||
describe('actions', () => {
|
||||
it('logout', () => {
|
||||
testAction({
|
||||
|
|
@ -100,30 +67,8 @@ describe('store/auth', () => {
|
|||
]
|
||||
})
|
||||
})
|
||||
it('check jwt null', () => {
|
||||
testAction({
|
||||
action: store.actions.check,
|
||||
params: {state: {}},
|
||||
expectedMutations: [
|
||||
{ type: 'authenticated', payload: false }
|
||||
]
|
||||
})
|
||||
})
|
||||
it('check jwt set', () => {
|
||||
testAction({
|
||||
action: store.actions.check,
|
||||
params: {state: {token: 'test', username: 'user'}},
|
||||
expectedMutations: [
|
||||
{ type: 'token', payload: 'test' }
|
||||
],
|
||||
expectedActions: [
|
||||
{ type: 'fetchProfile' },
|
||||
{ type: 'refreshToken' }
|
||||
]
|
||||
})
|
||||
})
|
||||
it('login success', () => {
|
||||
moxios.stubRequest('token/', {
|
||||
moxios.stubRequest('auth/login/', {
|
||||
status: 200,
|
||||
response: {
|
||||
token: 'test'
|
||||
|
|
@ -135,9 +80,7 @@ describe('store/auth', () => {
|
|||
testAction({
|
||||
action: store.actions.login,
|
||||
payload: {credentials: credentials},
|
||||
expectedMutations: [
|
||||
{ type: 'token', payload: 'test' }
|
||||
],
|
||||
expectedMutations: [],
|
||||
expectedActions: [
|
||||
{ type: 'fetchProfile' }
|
||||
]
|
||||
|
|
@ -187,18 +130,5 @@ describe('store/auth', () => {
|
|||
]
|
||||
})
|
||||
})
|
||||
it('refreshToken', () => {
|
||||
moxios.stubRequest('token/refresh/', {
|
||||
status: 200,
|
||||
response: {token: 'newtoken'}
|
||||
})
|
||||
testAction({
|
||||
action: store.actions.refreshToken,
|
||||
params: {state: {token: 'oldtoken'}},
|
||||
expectedMutations: [
|
||||
{ type: 'token', payload: 'newtoken' }
|
||||
]
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue