Add more tests for the new js modules
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
This commit is contained in:
parent
df4ca949f5
commit
c47a0a0153
File diff suppressed because one or more lines are too long
|
@ -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"
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -3298,4 +3298,4 @@ if(false) {}
|
|||
/***/ })
|
||||
|
||||
}]);
|
||||
//# sourceMappingURL=vue-2.js.map?v=83da49f0b3b2f4b45e68
|
||||
//# sourceMappingURL=vue-2.js.map?v=71b1f9cb73b6f972a0fe
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -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 New Issue