升级 Vite 并补齐管理子路径鉴权参数
This commit is contained in:
+46
-1
@@ -8,9 +8,11 @@ function fixture() {
|
||||
.replace(/^import .*$/gm, '')
|
||||
.replace('export default new vuex.Store(', 'globalThis.store = new vuex.Store(')
|
||||
const messages = []
|
||||
const showMessage = message => messages.push(message)
|
||||
showMessage.error = message => messages.push(message)
|
||||
const axios = {interceptors: {response: {use() {}}}}
|
||||
const context = vm.createContext({axios, vuex: {Store: function (config) {Object.assign(this, config)}},
|
||||
ElMessage: message => messages.push(message), URLSearchParams, console,
|
||||
ElMessage: showMessage, URLSearchParams, console,
|
||||
qs: {stringify: () => ''}})
|
||||
vm.runInContext(code, context)
|
||||
const store = context.store
|
||||
@@ -48,3 +50,46 @@ test('submission reloads persisted status without duplicating a completed task',
|
||||
assert.equal(store.state.totalGalleryTask[0].status, '下载完成')
|
||||
assert.equal(store.state.chosenGallery, false)
|
||||
})
|
||||
|
||||
test('gallery management subrequests carry the active auth code', async () => {
|
||||
const {store, axios, api} = fixture()
|
||||
store.state.AuthCode = 'test-auth'
|
||||
let call
|
||||
axios.post = async (...args) => {
|
||||
call = args
|
||||
return {data: {result: args[0].endsWith('/cache') ? 'failure' : 'success', data: 'expected test response'}}
|
||||
}
|
||||
await store.actions.reconnect(api)
|
||||
assert.equal(call[0], 'https://downloader.lionwebsite.xyz/GalleryManage/reconnect')
|
||||
assert.equal(call[1], null)
|
||||
assert.equal(call[2].params.AuthCode, 'test-auth')
|
||||
|
||||
await store.actions.readOnlineGallery(api, {link: 'https://example.org/g/1/key/', images: []})
|
||||
assert.equal(call[0], 'https://downloader.lionwebsite.xyz/GalleryManage/cache')
|
||||
assert.equal(call[1], null)
|
||||
assert.deepEqual({...call[2].params}, {
|
||||
url: 'https://example.org/g/1/key/',
|
||||
AuthCode: 'test-auth'
|
||||
})
|
||||
})
|
||||
|
||||
test('thumbnail and online image URLs carry the active auth code', () => {
|
||||
const {store} = fixture()
|
||||
store.state.AuthCode = 'code with spaces'
|
||||
store.mutations._updateGalleryTasks(store.state, [{
|
||||
gid: 123,
|
||||
name: 'sample',
|
||||
status: '已提交',
|
||||
thumb_link: 'https://example.org/thumb?a=1&b=2',
|
||||
createTime: 1,
|
||||
downloader: 7
|
||||
}])
|
||||
const thumbnail = new URL(store.state.totalGalleryTask[0].thumb_link)
|
||||
assert.equal(thumbnail.searchParams.get('AuthCode'), 'code with spaces')
|
||||
assert.equal(thumbnail.searchParams.get('path'), 'https://example.org/thumb?a=1&b=2')
|
||||
|
||||
store.mutations._setReadingGallery(store.state, {gid: 123, pages: 1})
|
||||
const image = new URL(store.state.readingGallery.images[0])
|
||||
assert.equal(image.searchParams.get('gid'), '123')
|
||||
assert.equal(image.searchParams.get('AuthCode'), 'code with spaces')
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user