Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ export default {
reporters: ['default'],
modulePaths: [compilerOptions.baseUrl],
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, { useESM: true }),
testMatch: ['<rootDir>/src/**/*.test.ts'],
testTimeout: 30000,
}
4 changes: 2 additions & 2 deletions src/__tests__/server.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ describe('Server Integration Tests', () => {
expect(response.statusCode).toBe(401)
})

it.skip('should return customers list with valid credentials', async () => {
it('should return customers list with valid credentials', async () => {
const response = await app.inject({
method: 'GET',
url: '/crm/v1/customers',
Expand Down Expand Up @@ -163,7 +163,7 @@ describe('Server Integration Tests', () => {
expect(body).toHaveProperty('openResourceDiscovery')
})

it.skip('should return tenant-aware, system-instance ORD document', async () => {
it('should return tenant-aware, system-instance ORD document', async () => {
const response = await app.inject({
method: 'GET',
url: '/open-resource-discovery/v1/documents/system-instance',
Expand Down
4 changes: 2 additions & 2 deletions src/api/health/v2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { healthCheckV2Config } from './config.js'
* This is a typical health check API for health probes
* as used by CloudFoundry or K8s
*/
export async function healthCheckV2Api(fastify: FastifyInstance): Promise<void> {
export function healthCheckV2Api(fastify: FastifyInstance): void {
fastify.log.info(`Registering ${healthCheckV2Config.apiName}...`)
fastify.get('/', async (req: FastifyRequest) => {
fastify.get('/', (req: FastifyRequest) => {
req.log.debug('Health Check invoked')
return {
status: 'OK',
Expand Down
35 changes: 23 additions & 12 deletions src/api/shared/validateUserAuthorization.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FastifyRequest } from 'fastify'
import { FastifyRequest, FastifyReply } from 'fastify'
import _ from 'lodash'
import { TenantConfiguration, tenants } from '../../data/user/tenants.js'
import { apiUsersAndPasswords } from '../../data/user/users.js'
Expand All @@ -24,18 +24,29 @@ const localTenants = Object.values(globalTenantIdToLocalTenantIdMapping)
*
* @throws UnauthorizedError
*/
export function validateUserAuthorization(username: string, password: string, req: FastifyRequest): void {
if (apiUsersAndPasswords[username] && apiUsersAndPasswords[username].password === password) {
const tenantId = apiUsersAndPasswords[username].tenantId
// Add user info to the request that we've validated
req.user = {
userName: username,
tenantId,
tenantConfiguration: tenants[tenantId],
export function validateUserAuthorization(
username: string,
password: string,
req: FastifyRequest,
_reply: FastifyReply,
done: (error?: Error) => void,
): void {
try {
if (apiUsersAndPasswords[username] && apiUsersAndPasswords[username].password === password) {
const tenantId = apiUsersAndPasswords[username].tenantId
// Add user info to the request that we've validated
req.user = {
userName: username,
tenantId,
tenantConfiguration: tenants[tenantId],
}
req.log.info(`User "${username}" of tenant "${tenantId}" authenticated successfully.`)
done()
} else {
done(new UnauthorizedError(`Unknown username "${username}" and password combination`))
}
req.log.info(`User "${username}" of tenant "${tenantId}" authenticated successfully.`)
} else {
throw new UnauthorizedError(`Unknown username "${username}" and password combination`)
} catch (error) {
done(error instanceof Error ? error : new Error('Authentication failed'))
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/event/odm-finance-costobject/v1/eventCatalogDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ export const openApiResourceName = 'openapi'
*
* This will later be referenced through ORD.
*/
export async function sapEventCatalogDefinition(fastify: FastifyInstance): Promise<void> {
export function sapEventCatalogDefinition(fastify: FastifyInstance): void {
fastify.get('/odm-finance-costobject.asyncapi2.json', {}, getSapEventCatalogDefinitionHandler)
}

async function getSapEventCatalogDefinitionHandler(req: CustomRequest): Promise<SapEventCatalog> {
function getSapEventCatalogDefinitionHandler(req: CustomRequest): SapEventCatalog {
const tenantIds = getTenantIdsFromHeader(req)
if (tenantIds.localTenantId) {
// This is the `sap.foo.bar:open-local-tenant-id:v1` access strategy
Expand Down