-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move provider controller to admin-api
- Loading branch information
1 parent
808d9ef
commit 3215127
Showing
6 changed files
with
177 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
apps/services/auth/admin-api/src/app/v2/providers/providers.controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { Controller, Get, UseGuards } from '@nestjs/common' | ||
import { | ||
Auth, | ||
CurrentAuth, | ||
IdsUserGuard, | ||
Scopes, | ||
ScopesGuard, | ||
} from '@island.is/auth-nest-tools' | ||
import { idsAdminScopes } from '@island.is/auth/scopes' | ||
import { ApiSecurity, ApiTags } from '@nestjs/swagger' | ||
import { Documentation } from '@island.is/nest/swagger' | ||
import { | ||
DelegationProviderService, | ||
PaginatedDelegationProviderDto, | ||
} from '@island.is/auth-api-lib' | ||
import { AuditService } from '@island.is/nest/audit' | ||
|
||
@UseGuards(IdsUserGuard, ScopesGuard) | ||
@Scopes(...idsAdminScopes) | ||
@ApiSecurity('ias', idsAdminScopes) | ||
@ApiTags('admin') | ||
@Controller({ | ||
path: '/providers', | ||
version: ['2'], | ||
}) | ||
export class ProvidersController { | ||
constructor( | ||
private readonly auditService: AuditService, | ||
private readonly delegationProviderService: DelegationProviderService, | ||
) {} | ||
|
||
@Get() | ||
@Documentation({ | ||
description: 'Fetch all delegationProviders and their delegationTypes', | ||
response: { status: 200, type: PaginatedDelegationProviderDto }, | ||
}) | ||
async getDelegationProviders( | ||
@CurrentAuth() auth: Auth, | ||
): Promise<PaginatedDelegationProviderDto> { | ||
return this.auditService.auditPromise( | ||
{ | ||
auth, | ||
action: 'getDelegationProviders', | ||
resources: (delegations) => delegations.data.map((d) => d.id), | ||
}, | ||
this.delegationProviderService.findAll(), | ||
) | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
apps/services/auth/admin-api/src/app/v2/providers/providers.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Module } from '@nestjs/common' | ||
import { | ||
ClientsModule, | ||
DelegationProviderService, | ||
} from '@island.is/auth-api-lib' | ||
import { ProvidersController } from './providers.controller' | ||
|
||
@Module({ | ||
imports: [ClientsModule], | ||
controllers: [ProvidersController], | ||
providers: [DelegationProviderService], | ||
}) | ||
export class ProvidersModule {} |
112 changes: 112 additions & 0 deletions
112
apps/services/auth/admin-api/src/app/v2/providers/test/provider-controller.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import { setupApp, TestApp } from '@island.is/testing/nest' | ||
import request from 'supertest' | ||
import { FixtureFactory } from '@island.is/services/auth/testing' | ||
import { | ||
DelegationProviderDto, | ||
SequelizeConfigService, | ||
} from '@island.is/auth-api-lib' | ||
import { AppModule } from '../../../app.module' | ||
import { createCurrentUser } from '@island.is/testing/fixtures' | ||
import { AdminPortalScope } from '@island.is/auth/scopes' | ||
|
||
const path = '/v2/providers' | ||
|
||
const delegationProviderTypesData = [ | ||
{ | ||
id: 'custom', | ||
delegationTypes: [ | ||
{ | ||
id: 'custom:1', | ||
name: 'custom:1', | ||
}, | ||
], | ||
}, | ||
{ | ||
id: 'procuration', | ||
delegationTypes: [ | ||
{ | ||
id: 'procuration:1', | ||
name: 'procuration:1', | ||
}, | ||
{ | ||
id: 'procuration:2', | ||
name: 'procuration:2', | ||
}, | ||
], | ||
}, | ||
] | ||
|
||
describe('ProverController', () => { | ||
let app: TestApp | ||
let server: request.SuperTest<request.Test> | ||
let factory: FixtureFactory | ||
|
||
describe('authentication and authorization', () => { | ||
it('user with no scopes should not have access to /providers', async () => { | ||
app = await setupApp({ | ||
AppModule, | ||
SequelizeConfigService, | ||
user: createCurrentUser(), | ||
dbType: 'postgres', | ||
}) | ||
server = request(app.getHttpServer()) | ||
factory = new FixtureFactory(app) | ||
|
||
const response = await server.get(path) | ||
|
||
expect(response.status).toBe(403) | ||
}) | ||
}) | ||
|
||
describe('getDelegationProviders', () => { | ||
beforeAll(async () => { | ||
const user = createCurrentUser({ | ||
scope: [AdminPortalScope.idsAdmin], | ||
}) | ||
|
||
app = await setupApp({ | ||
AppModule, | ||
SequelizeConfigService, | ||
user, | ||
dbType: 'postgres', | ||
}) | ||
server = request(app.getHttpServer()) | ||
factory = new FixtureFactory(app) | ||
|
||
for (const { id: dpId, delegationTypes } of delegationProviderTypesData) { | ||
for (const _ of delegationTypes) { | ||
await factory.createDelegationType({ providerId: dpId }) | ||
} | ||
} | ||
}) | ||
|
||
afterAll(async () => { | ||
await app.cleanUp() | ||
}) | ||
|
||
it('should return all delegation providers and their delegation types', async () => { | ||
// Act | ||
const response = await server.get(path) | ||
|
||
// Assert | ||
expect(response.status).toBe(200) | ||
expect(response.body.totalCount).toBe(delegationProviderTypesData.length) | ||
expect(response.body.data.length).toBe(delegationProviderTypesData.length) | ||
|
||
response.body.data.forEach((dp: DelegationProviderDto) => { | ||
const expectedDp = delegationProviderTypesData.find( | ||
({ id }) => id === dp.id, | ||
) | ||
|
||
expect(expectedDp).toBeDefined() | ||
expect(dp.delegationTypes.length).toBe( | ||
expectedDp?.delegationTypes.length, | ||
) | ||
}) | ||
}) | ||
}) | ||
|
||
afterAll(async () => { | ||
await app?.cleanUp() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters