Skip to content

Commit 819dbb8

Browse files
committed
show a session expired warning when the session runs out
1 parent 17294ca commit 819dbb8

3 files changed

Lines changed: 89 additions & 4 deletions

File tree

‎ui/public/locales/en.json‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2436,6 +2436,7 @@
24362436
"label.servicelist": "Services",
24372437
"label.serviceofferingid": "Compute Offering",
24382438
"label.serviceofferingname": "Compute Offering",
2439+
"label.session.expired": "Session Expired",
24392440
"label.sessions": "Active client sessions",
24402441
"label.set.default.nic": "Set default NIC",
24412442
"label.set.reservation": "Set reservation",
@@ -4020,6 +4021,7 @@
40204021
"message.select.zone.hint": "This is the type of Zone deployment that you want to use. Basic zone: provides a single Network where each Instance is assigned an IP directly from the Network. Guest isolation can be provided through layer-3 means such as security groups (IP address source filtering). Advanced zone: For more sophisticated Network topologies. This Network model provides the most flexibility in defining guest Networks and providing custom Network offerings such as firewall, VPN, or load balancer support.",
40214022
"message.server": "Server : ",
40224023
"message.server.description": "NFS, iSCSI, or PreSetup: IP address or DNS name of the storage device. VMWare PreSetup: IP address or DNS name of the vCenter server. Linstor: http(s) url of the linstor-controller.",
4024+
"message.session.expired": "Your session has expired. Please sign in again to continue.",
40234025
"message.set.default.nic": "Please confirm that you would like to make this NIC the default for this Instance.",
40244026
"message.set.default.nic.manual": "Please manually update the default NIC on the Instance now.",
40254027
"message.setting.updated": "Setting Updated:",

‎ui/src/utils/request.js‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,11 @@ const err = (error) => {
9595
} else if (originalPath !== '/user/login') {
9696
countNotify++
9797
store.commit('SET_COUNT_NOTIFY', countNotify)
98-
notification.error({
98+
notification.warning({
9999
top: '65px',
100-
message: i18n.global.t('label.unauthorized'),
101-
description: i18n.global.t('message.authorization.failed'),
100+
message: i18n.global.t('label.session.expired'),
101+
description: i18n.global.t('message.session.expired'),
102102
key: 'http-401',
103-
duration: 0,
104103
onClose: () => {
105104
let countNotify = store.getters.countNotify
106105
countNotify > 0 ? countNotify-- : countNotify = 0
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
import notification from 'ant-design-vue/es/notification'
19+
import router from '@/router'
20+
import store from '@/store'
21+
import { axios } from '@/utils/request'
22+
23+
jest.mock('ant-design-vue/es/notification', () => ({
24+
error: jest.fn(),
25+
warning: jest.fn(),
26+
warn: jest.fn()
27+
}))
28+
jest.mock('@/router', () => ({
29+
currentRoute: { value: { path: '/dashboard' } },
30+
push: jest.fn()
31+
}))
32+
jest.mock('@/store', () => ({
33+
getters: { countNotify: 0 },
34+
commit: jest.fn(),
35+
dispatch: jest.fn(() => Promise.resolve())
36+
}))
37+
jest.mock('@/locales', () => ({
38+
i18n: { global: { t: (key) => key } }
39+
}))
40+
jest.mock('@/vue-app', () => ({
41+
vueProps: { $localStorage: { get: () => null } }
42+
}))
43+
44+
const unauthorizedAdapter = (config) => Promise.reject(Object.assign(new Error('Request failed with status code 401'), {
45+
config,
46+
isAxiosError: true,
47+
response: {
48+
status: 401,
49+
config,
50+
data: { listvirtualmachinesresponse: { errorcode: 401, errortext: 'unable to verify user credentials and/or request signature' } }
51+
}
52+
}))
53+
54+
const callApi = () => axios.get('/client/api', {
55+
params: { command: 'listVirtualMachines' },
56+
adapter: unauthorizedAdapter
57+
}).catch(() => {})
58+
59+
describe('utils > request.js', () => {
60+
beforeEach(() => {
61+
jest.clearAllMocks()
62+
})
63+
64+
it('shows a session expired warning when the session times out', async () => {
65+
router.currentRoute.value.path = '/dashboard'
66+
await callApi()
67+
68+
expect(notification.error).not.toHaveBeenCalled()
69+
expect(notification.warning).toHaveBeenCalledTimes(1)
70+
const shown = notification.warning.mock.calls[0][0]
71+
expect(shown.message).toBe('label.session.expired')
72+
expect(shown.description).toBe('message.session.expired')
73+
expect(shown.duration).toBeUndefined()
74+
expect(store.dispatch).toHaveBeenCalledWith('Logout')
75+
})
76+
77+
it('shows nothing when already on the login page', async () => {
78+
router.currentRoute.value.path = '/user/login'
79+
await callApi()
80+
81+
expect(notification.error).not.toHaveBeenCalled()
82+
expect(notification.warning).not.toHaveBeenCalled()
83+
})
84+
})

0 commit comments

Comments
 (0)