Skip to content

Commit 7fc6fa3

Browse files
authored
Merge pull request #4266 from nextcloud/chore/session-middleware
2 parents a90ba5f + b86e40e commit 7fc6fa3

30 files changed

+365
-266
lines changed

β€Žcomposer/composer/autoload_classmap.phpβ€Ž

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php',
1010
'OCA\\Text\\AppInfo\\Application' => $baseDir . '/../lib/AppInfo/Application.php',
1111
'OCA\\Text\\Command\\ResetDocument' => $baseDir . '/../lib/Command/ResetDocument.php',
12+
'OCA\\Text\\Controller\\ASessionAwareController' => $baseDir . '/../lib/Controller/ASessionAwareController.php',
1213
'OCA\\Text\\Controller\\AttachmentController' => $baseDir . '/../lib/Controller/AttachmentController.php',
1314
'OCA\\Text\\Controller\\NavigationController' => $baseDir . '/../lib/Controller/NavigationController.php',
1415
'OCA\\Text\\Controller\\PublicSessionController' => $baseDir . '/../lib/Controller/PublicSessionController.php',
@@ -29,6 +30,7 @@
2930
'OCA\\Text\\Event\\LoadEditor' => $baseDir . '/../lib/Event/LoadEditor.php',
3031
'OCA\\Text\\Exception\\DocumentHasUnsavedChangesException' => $baseDir . '/../lib/Exception/DocumentHasUnsavedChangesException.php',
3132
'OCA\\Text\\Exception\\DocumentSaveConflictException' => $baseDir . '/../lib/Exception/DocumentSaveConflictException.php',
33+
'OCA\\Text\\Exception\\InvalidSessionException' => $baseDir . '/../lib/Exception/InvalidSessionException.php',
3234
'OCA\\Text\\Exception\\UploadException' => $baseDir . '/../lib/Exception/UploadException.php',
3335
'OCA\\Text\\Exception\\VersionMismatchException' => $baseDir . '/../lib/Exception/VersionMismatchException.php',
3436
'OCA\\Text\\Listeners\\BeforeNodeDeletedListener' => $baseDir . '/../lib/Listeners/BeforeNodeDeletedListener.php',
@@ -39,6 +41,8 @@
3941
'OCA\\Text\\Listeners\\LoadViewerListener' => $baseDir . '/../lib/Listeners/LoadViewerListener.php',
4042
'OCA\\Text\\Listeners\\NodeCopiedListener' => $baseDir . '/../lib/Listeners/NodeCopiedListener.php',
4143
'OCA\\Text\\Listeners\\RegisterDirectEditorEventListener' => $baseDir . '/../lib/Listeners/RegisterDirectEditorEventListener.php',
44+
'OCA\\Text\\Middleware\\Attribute\\RequireDocumentSession' => $baseDir . '/../lib/Middleware/Attribute/RequireDocumentSession.php',
45+
'OCA\\Text\\Middleware\\SessionMiddleware' => $baseDir . '/../lib/Middleware/SessionMiddleware.php',
4246
'OCA\\Text\\Migration\\ResetSessionsBeforeYjs' => $baseDir . '/../lib/Migration/ResetSessionsBeforeYjs.php',
4347
'OCA\\Text\\Migration\\Version010000Date20190617184535' => $baseDir . '/../lib/Migration/Version010000Date20190617184535.php',
4448
'OCA\\Text\\Migration\\Version030001Date20200402075029' => $baseDir . '/../lib/Migration/Version030001Date20200402075029.php',

β€Žcomposer/composer/autoload_static.phpβ€Ž

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class ComposerStaticInitText
2424
'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php',
2525
'OCA\\Text\\AppInfo\\Application' => __DIR__ . '/..' . '/../lib/AppInfo/Application.php',
2626
'OCA\\Text\\Command\\ResetDocument' => __DIR__ . '/..' . '/../lib/Command/ResetDocument.php',
27+
'OCA\\Text\\Controller\\ASessionAwareController' => __DIR__ . '/..' . '/../lib/Controller/ASessionAwareController.php',
2728
'OCA\\Text\\Controller\\AttachmentController' => __DIR__ . '/..' . '/../lib/Controller/AttachmentController.php',
2829
'OCA\\Text\\Controller\\NavigationController' => __DIR__ . '/..' . '/../lib/Controller/NavigationController.php',
2930
'OCA\\Text\\Controller\\PublicSessionController' => __DIR__ . '/..' . '/../lib/Controller/PublicSessionController.php',
@@ -44,6 +45,7 @@ class ComposerStaticInitText
4445
'OCA\\Text\\Event\\LoadEditor' => __DIR__ . '/..' . '/../lib/Event/LoadEditor.php',
4546
'OCA\\Text\\Exception\\DocumentHasUnsavedChangesException' => __DIR__ . '/..' . '/../lib/Exception/DocumentHasUnsavedChangesException.php',
4647
'OCA\\Text\\Exception\\DocumentSaveConflictException' => __DIR__ . '/..' . '/../lib/Exception/DocumentSaveConflictException.php',
48+
'OCA\\Text\\Exception\\InvalidSessionException' => __DIR__ . '/..' . '/../lib/Exception/InvalidSessionException.php',
4749
'OCA\\Text\\Exception\\UploadException' => __DIR__ . '/..' . '/../lib/Exception/UploadException.php',
4850
'OCA\\Text\\Exception\\VersionMismatchException' => __DIR__ . '/..' . '/../lib/Exception/VersionMismatchException.php',
4951
'OCA\\Text\\Listeners\\BeforeNodeDeletedListener' => __DIR__ . '/..' . '/../lib/Listeners/BeforeNodeDeletedListener.php',
@@ -54,6 +56,8 @@ class ComposerStaticInitText
5456
'OCA\\Text\\Listeners\\LoadViewerListener' => __DIR__ . '/..' . '/../lib/Listeners/LoadViewerListener.php',
5557
'OCA\\Text\\Listeners\\NodeCopiedListener' => __DIR__ . '/..' . '/../lib/Listeners/NodeCopiedListener.php',
5658
'OCA\\Text\\Listeners\\RegisterDirectEditorEventListener' => __DIR__ . '/..' . '/../lib/Listeners/RegisterDirectEditorEventListener.php',
59+
'OCA\\Text\\Middleware\\Attribute\\RequireDocumentSession' => __DIR__ . '/..' . '/../lib/Middleware/Attribute/RequireDocumentSession.php',
60+
'OCA\\Text\\Middleware\\SessionMiddleware' => __DIR__ . '/..' . '/../lib/Middleware/SessionMiddleware.php',
5761
'OCA\\Text\\Migration\\ResetSessionsBeforeYjs' => __DIR__ . '/..' . '/../lib/Migration/ResetSessionsBeforeYjs.php',
5862
'OCA\\Text\\Migration\\Version010000Date20190617184535' => __DIR__ . '/..' . '/../lib/Migration/Version010000Date20190617184535.php',
5963
'OCA\\Text\\Migration\\Version030001Date20200402075029' => __DIR__ . '/..' . '/../lib/Migration/Version030001Date20200402075029.php',
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*
2121
*/
2222

23-
import { randUser } from '../utils/index.js'
23+
import { randUser } from '../../utils/index.js'
2424

2525
const user = randUser()
2626
const messages = {
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/*
2+
* @copyright Copyright (c) 2022 Max <[email protected]>
3+
* @copyright Copyright (c) 2023 Julius HΓ€rtl <[email protected]>
4+
*
5+
* @author Max <[email protected]>
6+
* @author Julius HΓ€rtl <[email protected]>
7+
*
8+
* @license AGPL-3.0-or-later
9+
*
10+
* This program is free software: you can redistribute it and/or modify
11+
* it under the terms of the GNU Affero General Public License as
12+
* published by the Free Software Foundation, either version 3 of the
13+
* License, or (at your option) any later version.
14+
*
15+
* This program is distributed in the hope that it will be useful,
16+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
* GNU Affero General Public License for more details.
19+
*
20+
* You should have received a copy of the GNU Affero General Public License
21+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
22+
*
23+
*/
24+
25+
import { randUser } from '../../utils/index.js'
26+
27+
const user = randUser()
28+
29+
describe('The user mention API', function() {
30+
31+
before(function() {
32+
cy.createUser(user)
33+
window.OC = {
34+
config: { modRewriteWorking: false },
35+
webroot: '',
36+
}
37+
})
38+
39+
let fileId
40+
let requesttoken
41+
42+
beforeEach(function() {
43+
cy.login(user)
44+
cy.prepareSessionApi().then((token) => {
45+
requesttoken = token
46+
cy.uploadTestFile('test.md')
47+
.then(id => {
48+
fileId = id
49+
})
50+
})
51+
})
52+
53+
it('fetches users with valid session', function() {
54+
cy.createTextSession(fileId).then(connection => {
55+
cy.wrap(connection)
56+
.its('document.id')
57+
.should('equal', fileId)
58+
const requestData = {
59+
method: 'POST',
60+
url: '/apps/text/api/v1/users',
61+
body: {
62+
documentId: connection.document.id,
63+
sessionId: connection.session.id,
64+
sessionToken: connection.session.token,
65+
requesttoken,
66+
},
67+
failOnStatusCode: false,
68+
}
69+
70+
cy.request(requestData).then(({ status }) => {
71+
expect(status).to.eq(200)
72+
})
73+
74+
const invalidRequestData = { ...requestData }
75+
cy.wrap(() => {
76+
invalidRequestData.body = {
77+
...requestData.body,
78+
sessionToken: 'invalid',
79+
}
80+
})
81+
cy.request(invalidRequestData).then(({ status }) => {
82+
expect(status).to.eq(403)
83+
})
84+
85+
cy.wrap(() => {
86+
invalidRequestData.body = {
87+
...requestData.body,
88+
sessionId: 0,
89+
}
90+
})
91+
cy.request(invalidRequestData).then(({ status }) => {
92+
expect(status).to.eq(403)
93+
})
94+
95+
cy.wrap(() => {
96+
invalidRequestData.body = {
97+
...requestData.body,
98+
documentId: 0,
99+
}
100+
})
101+
cy.request(invalidRequestData).then(({ status }) => {
102+
expect(status).to.eq(403)
103+
})
104+
105+
cy.wrap(connection.close())
106+
107+
cy.request(requestData).then(({ status, body }) => {
108+
expect(status).to.eq(403)
109+
})
110+
})
111+
})
112+
})

β€Žcypress/support/sessions.jsβ€Ž

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@
2323
import SessionApi from '../../src/services/SessionApi.js'
2424
import { emit } from '@nextcloud/event-bus'
2525

26-
Cypress.Commands.add('prepareSessionApi', (fileId) => {
26+
Cypress.Commands.add('prepareSessionApi', () => {
2727
return cy.request('/csrftoken')
28-
.then(({ body }) => emit('csrf-token-update', body))
28+
.then(({ body }) => {
29+
emit('csrf-token-update', body)
30+
return body.token
31+
})
2932
})
3033

3134
Cypress.Commands.add('createTextSession', (fileId, options = {}) => {

β€Žjs/editor.jsβ€Ž

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Žjs/editor.js.mapβ€Ž

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Žjs/text-editors.jsβ€Ž

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Žjs/text-editors.js.mapβ€Ž

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Žjs/text-files.jsβ€Ž

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
Β (0)