Merge pull request #16979 from overleaf/jpa-join-project-remove-sl-1

[misc] joinProject: pass userId and anonymous access token in body 1/2

GitOrigin-RevId: 5d7832246c7262c004c2cd465d62488384b35ee3
This commit is contained in:
Jakob Ackermann
2024-02-12 09:03:16 +00:00
committed by Copybot
parent 19ba6c6a15
commit 974069bf1c
9 changed files with 165 additions and 6 deletions
+4 -1
View File
@@ -27,7 +27,10 @@ module.exports = {
pass: settings.apis.web.pass,
sendImmediately: true,
},
json: true,
json: {
userId,
anonymousAccessToken: user.anonymousAccessToken,
},
jar: false,
headers,
},
+1
View File
@@ -44,6 +44,7 @@
"mocha": "^10.2.0",
"sandboxed-module": "~0.3.0",
"sinon": "^9.2.4",
"sinon-chai": "^3.7.0",
"timekeeper": "0.0.4",
"typescript": "^5.0.4",
"uid-safe": "^2.1.5"
+4
View File
@@ -1,9 +1,13 @@
const chai = require('chai')
const SandboxedModule = require('sandboxed-module')
const sinon = require('sinon')
const chaiAsPromised = require('chai-as-promised')
const sinonChai = require('sinon-chai')
// Chai configuration
chai.should()
chai.use(chaiAsPromised)
chai.use(sinonChai)
// Global stubs
const sandbox = sinon.createSandbox()
@@ -68,7 +68,10 @@ describe('WebApiManager', function () {
pass: this.settings.apis.web.pass,
sendImmediately: true,
},
json: true,
json: {
userId: this.user_id,
anonymousAccessToken: undefined,
},
jar: false,
headers: {},
})
@@ -91,6 +94,65 @@ describe('WebApiManager', function () {
})
})
describe('with anon user', function () {
beforeEach(function () {
this.user_id = 'anonymous-user'
this.token = 'a-ro-token'
this.user = {
_id: this.user_id,
anonymousAccessToken: this.token,
}
this.response = {
project: { name: 'Test project' },
privilegeLevel: 'readOnly',
isRestrictedUser: true,
isTokenMember: false,
isInvitedMember: false,
}
this.request.post = sinon
.stub()
.yields(null, { statusCode: 200 }, this.response)
this.WebApiManager.joinProject(
this.project_id,
this.user,
this.callback
)
})
it('should send a request to web to join the project', function () {
this.request.post.should.have.been.calledWith({
url: `${this.settings.apis.web.url}/project/${this.project_id}/join`,
qs: {
user_id: this.user_id,
},
auth: {
user: this.settings.apis.web.user,
pass: this.settings.apis.web.pass,
sendImmediately: true,
},
json: {
userId: this.user_id,
anonymousAccessToken: this.token,
},
jar: false,
headers: { 'x-sl-anonymous-access-token': this.token },
})
})
it('should return the project, privilegeLevel, and restricted flag', function () {
this.callback.should.have.been.calledWith(
null,
this.response.project,
this.response.privilegeLevel,
{
isRestrictedUser: this.response.isRestrictedUser,
isTokenMember: this.response.isTokenMember,
isInvitedMember: this.response.isInvitedMember,
}
)
})
})
describe('when web replies with a 403', function () {
beforeEach(function () {
this.request.post = sinon