mirror of
https://github.com/baserow/baserow.git
synced 2026-12-04 00:08:25 +00:00
* feat: let visitors report abuse on published applications * fix: let logged-in app users report published applications
42 lines
1.5 KiB
JavaScript
42 lines
1.5 KiB
JavaScript
import { prepareUserSourceRequestHeaders } from '@baserow/modules/core/plugins/userSourceClientHandler'
|
|
|
|
function createStore({ baserowUserAuthenticated = false } = {}) {
|
|
const application = { id: 1 }
|
|
return {
|
|
getters: {
|
|
'userSourceUser/getCurrentApplication': application,
|
|
'userSourceUser/isAuthenticated': () => true,
|
|
'userSourceUser/isRefreshing': () => false,
|
|
'userSourceUser/accessToken': () => 'app-user-token',
|
|
'auth/isAuthenticated': baserowUserAuthenticated,
|
|
},
|
|
}
|
|
}
|
|
|
|
describe('prepareUserSourceRequestHeaders', () => {
|
|
test('sends the user source token of a logged in visitor', () => {
|
|
const config = prepareUserSourceRequestHeaders(createStore())({})
|
|
|
|
expect(config.headers.Authorization).toBe('JWT app-user-token')
|
|
expect(config.usesUserSourceAuthorization).toBe(true)
|
|
})
|
|
|
|
test('sends no user source token when the request opts out', () => {
|
|
const config = prepareUserSourceRequestHeaders(createStore())({
|
|
skipUserSourceAuthorization: true,
|
|
})
|
|
|
|
expect(config.headers?.Authorization).toBeUndefined()
|
|
expect(config.headers?.UserSourceAuthorization).toBeUndefined()
|
|
expect(config.usesUserSourceAuthorization).toBeUndefined()
|
|
})
|
|
|
|
test('sends no user source header next to a Baserow user when opting out', () => {
|
|
const config = prepareUserSourceRequestHeaders(
|
|
createStore({ baserowUserAuthenticated: true })
|
|
)({ skipUserSourceAuthorization: true })
|
|
|
|
expect(config.headers?.UserSourceAuthorization).toBeUndefined()
|
|
})
|
|
})
|