Compare commits

...

4 Commits

38 changed files with 185 additions and 20 deletions

View File

@@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [2.34.3](https://github.com/standardnotes/server/compare/@standardnotes/analytics@2.34.2...@standardnotes/analytics@2.34.3) (2023-11-28)
**Note:** Version bump only for package @standardnotes/analytics
## [2.34.2](https://github.com/standardnotes/server/compare/@standardnotes/analytics@2.34.1...@standardnotes/analytics@2.34.2) (2023-11-28)
**Note:** Version bump only for package @standardnotes/analytics

View File

@@ -1,6 +1,6 @@
{
"name": "@standardnotes/analytics",
"version": "2.34.2",
"version": "2.34.3",
"engines": {
"node": ">=18.0.0 <21.0.0"
},

View File

@@ -3,6 +3,12 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [1.87.3](https://github.com/standardnotes/server/compare/@standardnotes/api-gateway@1.87.2...@standardnotes/api-gateway@1.87.3) (2023-11-28)
### Bug Fixes
* **api-gateway:** add session to response locals from web socket middleware ([4cc647a](https://github.com/standardnotes/server/commit/4cc647ac07b2471d6616a913bcdca431c506fd0e))
## [1.87.2](https://github.com/standardnotes/server/compare/@standardnotes/api-gateway@1.87.1...@standardnotes/api-gateway@1.87.2) (2023-11-28)
**Note:** Version bump only for package @standardnotes/api-gateway

View File

@@ -1,6 +1,6 @@
{
"name": "@standardnotes/api-gateway",
"version": "1.87.2",
"version": "1.87.3",
"engines": {
"node": ">=18.0.0 <21.0.0"
},

View File

@@ -60,6 +60,7 @@ export class WebSocketAuthMiddleware extends BaseMiddleware {
const decodedToken = <CrossServiceTokenData>verify(crossServiceToken, this.jwtSecret, { algorithms: ['HS256'] })
response.locals.user = decodedToken.user
response.locals.session = decodedToken.session
response.locals.roles = decodedToken.roles
} catch (error) {
const errorMessage = (error as AxiosError).isAxiosError

View File

@@ -3,6 +3,13 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [1.174.3](https://github.com/standardnotes/server/compare/@standardnotes/auth-server@1.174.2...@standardnotes/auth-server@1.174.3) (2023-11-28)
### Bug Fixes
* **auth:** pass session uuid to web sockets controller ([edb0a76](https://github.com/standardnotes/server/commit/edb0a768d0b8c31298b31372e6cec16d003fd28d))
* pass session uuid to websockets token ([bcd1d83](https://github.com/standardnotes/server/commit/bcd1d830e6125fc5f8cc1312e581284221aaac8f))
## [1.174.2](https://github.com/standardnotes/server/compare/@standardnotes/auth-server@1.174.1...@standardnotes/auth-server@1.174.2) (2023-11-28)
**Note:** Version bump only for package @standardnotes/auth-server

View File

@@ -1,6 +1,6 @@
{
"name": "@standardnotes/auth-server",
"version": "1.174.2",
"version": "1.174.3",
"engines": {
"node": ">=18.0.0 <21.0.0"
},

View File

@@ -1195,6 +1195,7 @@ export class ContainerConfigLoader {
container.get<GetRegularSubscriptionForUser>(TYPES.Auth_GetRegularSubscriptionForUser),
container.get<GetSubscriptionSetting>(TYPES.Auth_GetSubscriptionSetting),
container.get<SharedVaultUserRepositoryInterface>(TYPES.Auth_SharedVaultUserRepository),
container.get<GetActiveSessionsForUser>(TYPES.Auth_GetActiveSessionsForUser),
),
)
container.bind<ProcessUserRequest>(TYPES.Auth_ProcessUserRequest).to(ProcessUserRequest)

View File

@@ -22,6 +22,7 @@ import { GetRegularSubscriptionForUser } from '../GetRegularSubscriptionForUser/
import { UserSubscription } from '../../Subscription/UserSubscription'
import { SubscriptionSetting } from '../../Setting/SubscriptionSetting'
import { EncryptionVersion } from '../../Encryption/EncryptionVersion'
import { GetActiveSessionsForUser } from '../GetActiveSessionsForUser'
describe('CreateCrossServiceToken', () => {
let userProjector: ProjectorInterface<User>
@@ -32,6 +33,7 @@ describe('CreateCrossServiceToken', () => {
let getRegularSubscription: GetRegularSubscriptionForUser
let getSubscriptionSetting: GetSubscriptionSetting
let sharedVaultUserRepository: SharedVaultUserRepositoryInterface
let getActiveSessionsForUser: GetActiveSessionsForUser
const jwtTTL = 60
let session: Session
@@ -49,11 +51,15 @@ describe('CreateCrossServiceToken', () => {
getRegularSubscription,
getSubscriptionSetting,
sharedVaultUserRepository,
getActiveSessionsForUser,
)
beforeEach(() => {
session = {} as jest.Mocked<Session>
getActiveSessionsForUser = {} as jest.Mocked<GetActiveSessionsForUser>
getActiveSessionsForUser.execute = jest.fn().mockReturnValue({ sessions: [session] })
user = {
uuid: '00000000-0000-0000-0000-000000000000',
email: 'test@test.te',
@@ -195,6 +201,69 @@ describe('CreateCrossServiceToken', () => {
)
})
it('should create a cross service token for a user and a specific session', async () => {
await createUseCase().execute({
userUuid: '00000000-0000-0000-0000-000000000000',
sessionUuid: '00000000-0000-0000-0000-000000000000',
})
expect(tokenEncoder.encodeExpirableToken).toHaveBeenCalledWith(
{
roles: [
{
name: 'role1',
uuid: '1-3-4',
},
],
belongs_to_shared_vaults: [
{
shared_vault_uuid: '00000000-0000-0000-0000-000000000000',
permission: 'read',
},
],
session: {
test: 'test',
},
user: {
email: 'test@test.te',
uuid: '00000000-0000-0000-0000-000000000000',
},
},
60,
)
})
it('should create a cross service token for a user and specific session if the session is missing', async () => {
getActiveSessionsForUser.execute = jest.fn().mockReturnValue({ sessions: [] })
await createUseCase().execute({
userUuid: '00000000-0000-0000-0000-000000000000',
sessionUuid: '00000000-0000-0000-0000-000000000000',
})
expect(tokenEncoder.encodeExpirableToken).toHaveBeenCalledWith(
{
roles: [
{
name: 'role1',
uuid: '1-3-4',
},
],
belongs_to_shared_vaults: [
{
shared_vault_uuid: '00000000-0000-0000-0000-000000000000',
permission: 'read',
},
],
user: {
email: 'test@test.te',
uuid: '00000000-0000-0000-0000-000000000000',
},
},
60,
)
})
it('should throw an error if user does not exist', async () => {
userRepository.findOneByUuid = jest.fn().mockReturnValue(null)

View File

@@ -11,6 +11,7 @@ import { CreateCrossServiceTokenDTO } from './CreateCrossServiceTokenDTO'
import { SharedVaultUserRepositoryInterface } from '../../SharedVault/SharedVaultUserRepositoryInterface'
import { GetSubscriptionSetting } from '../GetSubscriptionSetting/GetSubscriptionSetting'
import { GetRegularSubscriptionForUser } from '../GetRegularSubscriptionForUser/GetRegularSubscriptionForUser'
import { GetActiveSessionsForUser } from '../GetActiveSessionsForUser'
export class CreateCrossServiceToken implements UseCaseInterface<string> {
constructor(
@@ -23,6 +24,7 @@ export class CreateCrossServiceToken implements UseCaseInterface<string> {
private getRegularSubscription: GetRegularSubscriptionForUser,
private getSubscriptionSettingUseCase: GetSubscriptionSetting,
private sharedVaultUserRepository: SharedVaultUserRepositoryInterface,
private getActiveSessions: GetActiveSessionsForUser,
) {}
async execute(dto: CreateCrossServiceTokenDTO): Promise<Result<string>> {
@@ -84,6 +86,14 @@ export class CreateCrossServiceToken implements UseCaseInterface<string> {
if (dto.session !== undefined) {
authTokenData.session = this.projectSession(dto.session)
} else if (dto.sessionUuid !== undefined) {
const activeSessionsResponse = await this.getActiveSessions.execute({
userUuid: user.uuid,
sessionUuid: dto.sessionUuid,
})
if (activeSessionsResponse.sessions.length) {
authTokenData.session = this.projectSession(activeSessionsResponse.sessions[0])
}
}
return Result.ok(this.tokenEncoder.encodeExpirableToken(authTokenData, this.jwtTTL))

View File

@@ -10,5 +10,6 @@ export type CreateCrossServiceTokenDTO = Either<
},
{
userUuid: string
sessionUuid?: string
}
>

View File

@@ -65,4 +65,10 @@ describe('GetActiveSessionsForUser', () => {
expect(sessionRepository.findAllByRefreshExpirationAndUserUuid).toHaveBeenCalledWith('1-2-3')
})
it('should get a single session for a user', async () => {
expect(await createUseCase().execute({ userUuid: '1-2-3', sessionUuid: '2-3-4' })).toEqual({
sessions: [session2],
})
})
})

View File

@@ -5,6 +5,7 @@ import { SessionRepositoryInterface } from '../Session/SessionRepositoryInterfac
import { GetActiveSessionsForUserDTO } from './GetActiveSessionsForUserDTO'
import { GetActiveSessionsForUserResponse } from './GetActiveSessionsForUserResponse'
import { UseCaseInterface } from './UseCaseInterface'
import { Session } from '../Session/Session'
@injectable()
export class GetActiveSessionsForUser implements UseCaseInterface {
@@ -18,13 +19,26 @@ export class GetActiveSessionsForUser implements UseCaseInterface {
const ephemeralSessions = await this.ephemeralSessionRepository.findAllByUserUuid(dto.userUuid)
const sessions = await this.sessionRepository.findAllByRefreshExpirationAndUserUuid(dto.userUuid)
return {
sessions: sessions.concat(ephemeralSessions).sort((a, b) => {
const dateA = a.refreshExpiration instanceof Date ? a.refreshExpiration : new Date(a.refreshExpiration)
const dateB = b.refreshExpiration instanceof Date ? b.refreshExpiration : new Date(b.refreshExpiration)
const activeSessions = sessions.concat(ephemeralSessions).sort((a, b) => {
const dateA = a.refreshExpiration instanceof Date ? a.refreshExpiration : new Date(a.refreshExpiration)
const dateB = b.refreshExpiration instanceof Date ? b.refreshExpiration : new Date(b.refreshExpiration)
return dateB.getTime() - dateA.getTime()
}),
return dateB.getTime() - dateA.getTime()
})
if (dto.sessionUuid) {
let sessions: Session[] = []
const session = activeSessions.find((session) => session.uuid === dto.sessionUuid)
if (session) {
sessions = [session]
}
return {
sessions,
}
}
return {
sessions: activeSessions,
}
}
}

View File

@@ -1,3 +1,4 @@
export type GetActiveSessionsForUserDTO = {
userUuid: string
sessionUuid?: string
}

View File

@@ -48,6 +48,7 @@ export class BaseWebSocketsController extends BaseHttpController {
const resultOrError = await this.createCrossServiceToken.execute({
userUuid: token.userUuid,
sessionUuid: token.sessionUuid,
})
if (resultOrError.isFailed()) {
return this.json(

View File

@@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [1.22.3](https://github.com/standardnotes/server/compare/@standardnotes/domain-events-infra@1.22.2...@standardnotes/domain-events-infra@1.22.3) (2023-11-28)
**Note:** Version bump only for package @standardnotes/domain-events-infra
## [1.22.2](https://github.com/standardnotes/server/compare/@standardnotes/domain-events-infra@1.22.1...@standardnotes/domain-events-infra@1.22.2) (2023-11-28)
**Note:** Version bump only for package @standardnotes/domain-events-infra

View File

@@ -1,6 +1,6 @@
{
"name": "@standardnotes/domain-events-infra",
"version": "1.22.2",
"version": "1.22.3",
"engines": {
"node": ">=18.0.0 <21.0.0"
},

View File

@@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [2.138.1](https://github.com/standardnotes/server/compare/@standardnotes/domain-events@2.138.0...@standardnotes/domain-events@2.138.1) (2023-11-28)
**Note:** Version bump only for package @standardnotes/domain-events
# [2.138.0](https://github.com/standardnotes/server/compare/@standardnotes/domain-events@2.137.1...@standardnotes/domain-events@2.138.0) (2023-11-28)
### Features

View File

@@ -1,6 +1,6 @@
{
"name": "@standardnotes/domain-events",
"version": "2.138.0",
"version": "2.138.1",
"engines": {
"node": ">=18.0.0 <21.0.0"
},

View File

@@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [1.36.3](https://github.com/standardnotes/server/compare/@standardnotes/files-server@1.36.2...@standardnotes/files-server@1.36.3) (2023-11-28)
**Note:** Version bump only for package @standardnotes/files-server
## [1.36.2](https://github.com/standardnotes/server/compare/@standardnotes/files-server@1.36.1...@standardnotes/files-server@1.36.2) (2023-11-28)
**Note:** Version bump only for package @standardnotes/files-server

View File

@@ -1,6 +1,6 @@
{
"name": "@standardnotes/files-server",
"version": "1.36.2",
"version": "1.36.3",
"engines": {
"node": ">=18.0.0 <21.0.0"
},

View File

@@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [1.22.3](https://github.com/standardnotes/server/compare/@standardnotes/home-server@1.22.2...@standardnotes/home-server@1.22.3) (2023-11-28)
**Note:** Version bump only for package @standardnotes/home-server
## [1.22.2](https://github.com/standardnotes/server/compare/@standardnotes/home-server@1.22.1...@standardnotes/home-server@1.22.2) (2023-11-28)
**Note:** Version bump only for package @standardnotes/home-server

View File

@@ -1,6 +1,6 @@
{
"name": "@standardnotes/home-server",
"version": "1.22.2",
"version": "1.22.3",
"engines": {
"node": ">=18.0.0 <21.0.0"
},

View File

@@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [1.51.3](https://github.com/standardnotes/server/compare/@standardnotes/revisions-server@1.51.2...@standardnotes/revisions-server@1.51.3) (2023-11-28)
**Note:** Version bump only for package @standardnotes/revisions-server
## [1.51.2](https://github.com/standardnotes/server/compare/@standardnotes/revisions-server@1.51.1...@standardnotes/revisions-server@1.51.2) (2023-11-28)
**Note:** Version bump only for package @standardnotes/revisions-server

View File

@@ -1,6 +1,6 @@
{
"name": "@standardnotes/revisions-server",
"version": "1.51.2",
"version": "1.51.3",
"engines": {
"node": ">=18.0.0 <21.0.0"
},

View File

@@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [1.27.8](https://github.com/standardnotes/server/compare/@standardnotes/scheduler-server@1.27.7...@standardnotes/scheduler-server@1.27.8) (2023-11-28)
**Note:** Version bump only for package @standardnotes/scheduler-server
## [1.27.7](https://github.com/standardnotes/server/compare/@standardnotes/scheduler-server@1.27.6...@standardnotes/scheduler-server@1.27.7) (2023-11-28)
**Note:** Version bump only for package @standardnotes/scheduler-server

View File

@@ -1,6 +1,6 @@
{
"name": "@standardnotes/scheduler-server",
"version": "1.27.7",
"version": "1.27.8",
"engines": {
"node": ">=18.0.0 <21.0.0"
},

View File

@@ -3,6 +3,12 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [1.17.2](https://github.com/standardnotes/server/compare/@standardnotes/security@1.17.1...@standardnotes/security@1.17.2) (2023-11-28)
### Bug Fixes
* pass session uuid to websockets token ([bcd1d83](https://github.com/standardnotes/server/commit/bcd1d830e6125fc5f8cc1312e581284221aaac8f))
## [1.17.1](https://github.com/standardnotes/server/compare/@standardnotes/security@1.17.0...@standardnotes/security@1.17.1) (2023-11-27)
### Bug Fixes

View File

@@ -1,6 +1,6 @@
{
"name": "@standardnotes/security",
"version": "1.17.1",
"version": "1.17.2",
"engines": {
"node": ">=18.0.0 <21.0.0"
},

View File

@@ -1,3 +1,4 @@
export type WebSocketConnectionTokenData = {
userUuid: string
sessionUuid: string
}

View File

@@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [1.127.1](https://github.com/standardnotes/server/compare/@standardnotes/syncing-server@1.127.0...@standardnotes/syncing-server@1.127.1) (2023-11-28)
**Note:** Version bump only for package @standardnotes/syncing-server
# [1.127.0](https://github.com/standardnotes/server/compare/@standardnotes/syncing-server@1.126.1...@standardnotes/syncing-server@1.127.0) (2023-11-28)
### Features

View File

@@ -1,6 +1,6 @@
{
"name": "@standardnotes/syncing-server",
"version": "1.127.0",
"version": "1.127.1",
"engines": {
"node": ">=18.0.0 <21.0.0"
},

View File

@@ -3,6 +3,12 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [1.21.1](https://github.com/standardnotes/server/compare/@standardnotes/websockets-server@1.21.0...@standardnotes/websockets-server@1.21.1) (2023-11-28)
### Bug Fixes
* pass session uuid to websockets token ([bcd1d83](https://github.com/standardnotes/server/commit/bcd1d830e6125fc5f8cc1312e581284221aaac8f))
# [1.21.0](https://github.com/standardnotes/server/compare/@standardnotes/websockets-server@1.20.4...@standardnotes/websockets-server@1.21.0) (2023-11-28)
### Features

View File

@@ -1,6 +1,6 @@
{
"name": "@standardnotes/websockets-server",
"version": "1.21.0",
"version": "1.21.1",
"engines": {
"node": ">=18.0.0 <21.0.0"
},

View File

@@ -16,10 +16,10 @@ describe('CreateWebSocketConnection', () => {
})
it('should create a web socket connection token', async () => {
const result = await createUseCase().execute({ userUuid: '1-2-3' })
const result = await createUseCase().execute({ userUuid: '1-2-3', sessionUuid: '4-5-6' })
expect(result.token).toEqual('foobar')
expect(tokenEncoder.encodeExpirableToken).toHaveBeenCalledWith({ userUuid: '1-2-3' }, 30)
expect(tokenEncoder.encodeExpirableToken).toHaveBeenCalledWith({ userUuid: '1-2-3', sessionUuid: '4-5-6' }, 30)
})
})

View File

@@ -1,3 +1,4 @@
export type CreateWebSocketConnectionDTO = {
userUuid: string
sessionUuid: string
}

View File

@@ -17,6 +17,7 @@ export class CreateWebSocketConnectionToken implements UseCaseInterface {
async execute(dto: CreateWebSocketConnectionDTO): Promise<CreateWebSocketConnectionResponse> {
const data: WebSocketConnectionTokenData = {
userUuid: dto.userUuid,
sessionUuid: dto.sessionUuid,
}
return {

View File

@@ -28,6 +28,7 @@ export class AnnotatedWebSocketsController extends BaseHttpController {
async createConnectionToken(_request: Request, response: Response): Promise<results.JsonResult> {
const result = await this.createWebSocketConnectionToken.execute({
userUuid: response.locals.user.uuid,
sessionUuid: response.locals.session.uuid,
})
return this.json(result)