Merge pull request #19389 from nextcloud/test/js-api
Test request token logic a bit more
This commit is contained in:
commit
db5ffc6d94
16 changed files with 53 additions and 42 deletions
BIN
apps/files_sharing/js/dist/personal-settings.js.map
vendored
BIN
apps/files_sharing/js/dist/personal-settings.js.map
vendored
Binary file not shown.
|
@ -20,7 +20,7 @@
|
|||
-->
|
||||
|
||||
<template>
|
||||
<div id="files-sharing-personal-settings" class="section" v-if="!enforceAcceptShares">
|
||||
<div v-if="!enforceAcceptShares" id="files-sharing-personal-settings" class="section">
|
||||
<h2>{{ t('files', 'Sharing') }}</h2>
|
||||
<p>
|
||||
<input id="files-sharing-personal-settings-accept"
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
core/js/dist/login.js
vendored
BIN
core/js/dist/login.js
vendored
Binary file not shown.
BIN
core/js/dist/login.js.map
vendored
BIN
core/js/dist/login.js.map
vendored
Binary file not shown.
BIN
core/js/dist/main.js
vendored
BIN
core/js/dist/main.js
vendored
Binary file not shown.
BIN
core/js/dist/main.js.map
vendored
BIN
core/js/dist/main.js.map
vendored
Binary file not shown.
BIN
core/js/dist/maintenance.js
vendored
BIN
core/js/dist/maintenance.js
vendored
Binary file not shown.
BIN
core/js/dist/maintenance.js.map
vendored
BIN
core/js/dist/maintenance.js.map
vendored
Binary file not shown.
|
@ -21,20 +21,35 @@
|
|||
|
||||
import { emit } from '@nextcloud/event-bus'
|
||||
|
||||
let token = document.getElementsByTagName('head')[0].getAttribute('data-requesttoken')
|
||||
/**
|
||||
* @private
|
||||
* @param {Document} global the document to read the initial value from
|
||||
* @param {Function} emit the function to invoke for every new token
|
||||
* @returns {Object}
|
||||
*/
|
||||
export const manageToken = (global, emit) => {
|
||||
let token = global.getElementsByTagName('head')[0].getAttribute('data-requesttoken')
|
||||
|
||||
return {
|
||||
getToken: () => token,
|
||||
setToken: newToken => {
|
||||
token = newToken
|
||||
|
||||
emit('csrf-token-update', {
|
||||
token,
|
||||
})
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
const manageFromDocument = manageToken(document, emit)
|
||||
|
||||
/**
|
||||
* @returns {string}
|
||||
*/
|
||||
export const getToken = () => token
|
||||
export const getToken = manageFromDocument.getToken
|
||||
|
||||
/**
|
||||
* @param {String} newToken new token
|
||||
*/
|
||||
export const setToken = newToken => {
|
||||
token = newToken
|
||||
|
||||
emit('csrf-token-update', {
|
||||
token,
|
||||
})
|
||||
}
|
||||
export const setToken = manageFromDocument.setToken
|
||||
|
|
|
@ -1,29 +0,0 @@
|
|||
/*
|
||||
* @copyright Copyright (c) 2019 Roeland Jago Douma <roeland@famdouma.nl>
|
||||
*
|
||||
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @namespace OCP.InitialState
|
||||
*/
|
||||
|
||||
import { loadState as load } from '@nextcloud/initial-state'
|
||||
|
||||
export const loadState = load
|
|
@ -103,14 +103,14 @@ export const initSessionHeartBeat = () => {
|
|||
|
||||
// Let apps know we're online and requests will have the new token
|
||||
emit('networkOnline', {
|
||||
success: true
|
||||
success: true,
|
||||
})
|
||||
} catch (e) {
|
||||
console.error('could not update session token after resuming network', e)
|
||||
|
||||
// Let apps know we're online but requests might have an outdated token
|
||||
emit('networkOnline', {
|
||||
success: false
|
||||
success: false,
|
||||
})
|
||||
}
|
||||
})
|
||||
|
|
|
@ -19,12 +19,37 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {JSDOM} from 'jsdom'
|
||||
import {subscribe, unsubscribe} from '@nextcloud/event-bus'
|
||||
|
||||
import {setToken} from '../../OC/requesttoken'
|
||||
import {manageToken, setToken} from '../../OC/requesttoken'
|
||||
|
||||
describe('request token', () => {
|
||||
|
||||
let dom
|
||||
let emit
|
||||
let manager
|
||||
const token = 'abc123'
|
||||
|
||||
beforeEach(() => {
|
||||
dom = new JSDOM()
|
||||
emit = sinon.spy()
|
||||
const head = dom.window.document.getElementsByTagName('head')[0]
|
||||
head.setAttribute('data-requesttoken', token)
|
||||
|
||||
manager = manageToken(dom.window.document, emit)
|
||||
})
|
||||
|
||||
it('reads the token from the document', () => {
|
||||
expect(manager.getToken()).to.equal('abc123')
|
||||
})
|
||||
|
||||
it('remembers the updated token', () => {
|
||||
manager.setToken('bca321')
|
||||
|
||||
expect(manager.getToken()).to.equal('bca321')
|
||||
})
|
||||
|
||||
describe('@nextcloud/auth integration', () => {
|
||||
let listener
|
||||
|
||||
|
|
Loading…
Reference in a new issue