Skip to content

Commit

Permalink
feat(saml): add the new resource
Browse files Browse the repository at this point in the history
  • Loading branch information
gdostie committed Dec 11, 2019
1 parent bdb7b90 commit d6883fe
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/resources/PlatformResources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import MachineLearning from './MachineLearning/MachineLearning';
import Organization from './Organizations/Organization';
import Pipelines from './Pipelines/Pipelines';
import Resource from './Resource';
import Saml from './Saml/Saml';
import SecurityCache from './SecurityCache/SecurityCache';
import Sources from './Sources/Sources';

Expand All @@ -28,6 +29,7 @@ const resourcesMap: Array<{key: string; resource: typeof Resource}> = [
{key: 'pipeline', resource: Pipelines},
{key: 'source', resource: Sources},
{key: 'field', resource: Field},
{key: 'saml', resource: Saml},
];

class PlatformResources {
Expand All @@ -46,6 +48,7 @@ class PlatformResources {
pipeline: Pipelines;
source: Sources;
field: Field;
saml: Saml;

registerAll() {
resourcesMap.forEach(({key, resource}) => {
Expand Down
37 changes: 37 additions & 0 deletions src/resources/Saml/Saml.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import API from '../../APICore';
import {New} from '../BaseInterfaces';
import {RealmModel} from '../Groups';
import Resource from '../Resource';
import {SamlIdentityProviderEnabledModel, SamlIdentityProviderModel} from './SamlInterfaces';

export default class Saml extends Resource {
static baseUrl = `/rest/organizations/${API.orgPlaceholder}/saml`;

isEnabled() {
return this.api.get<SamlIdentityProviderEnabledModel>(`${Saml.baseUrl}/enabled`);
}

listAvailableProviders() {
return this.api.get<SamlIdentityProviderModel[]>(`${Saml.baseUrl}/availables`);
}

deleteProvider() {
return this.api.delete(`${Saml.baseUrl}/identityProvider`);
}

getProvider() {
return this.api.get<SamlIdentityProviderModel>(`${Saml.baseUrl}/identityProvider`);
}

create(identityProvider: New<SamlIdentityProviderModel>) {
return this.api.post<SamlIdentityProviderModel>(`${Saml.baseUrl}/identityProvider`, identityProvider);
}

update(identityProvider: SamlIdentityProviderModel) {
return this.api.put<SamlIdentityProviderModel>(`${Saml.baseUrl}/identityProvider`, identityProvider);
}

listRealms() {
return this.api.get<RealmModel[]>(`${Saml.baseUrl}/identityProvider/realms`);
}
}
15 changes: 15 additions & 0 deletions src/resources/Saml/SamlInterfaces.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import {IdAndDisplayNameModel} from '../BaseInterfaces';

export interface SamlIdentityProviderEnabledModel {
organizationId: string;
samlEnabled: boolean;
}

export interface SamlIdentityProviderModel {
displayName: string;
entityId: string;
id: string;
organizationIds: IdAndDisplayNameModel[];
postBindingEndpoint: string;
x509Certificate: string;
}
2 changes: 2 additions & 0 deletions src/resources/Saml/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './Saml';
export * from './SamlInterfaces';
97 changes: 97 additions & 0 deletions src/resources/Saml/tests/Saml.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import API from '../../../APICore';
import {New} from '../../BaseInterfaces';
import Saml from '../Saml';
import {SamlIdentityProviderModel} from '../SamlInterfaces';

jest.mock('../../../APICore');

const APIMock: jest.Mock<API> = API as any;

describe('Saml', () => {
let saml: Saml;
const api = new APIMock() as jest.Mocked<API>;

beforeEach(() => {
jest.clearAllMocks();
saml = new Saml(api);
});

describe('isEnabled', () => {
it('should make a GET call to "/saml/enabled"', () => {
saml.isEnabled();
expect(api.get).toHaveBeenCalledTimes(1);
expect(api.get).toHaveBeenCalledWith('/rest/organizations/{organizationName}/saml/enabled');
});
});

describe('listAvailableProviders', () => {
it('should make a GET call to "/saml/availables"', () => {
saml.listAvailableProviders();
expect(api.get).toHaveBeenCalledTimes(1);
expect(api.get).toHaveBeenCalledWith('/rest/organizations/{organizationName}/saml/availables');
});
});

describe('getProvider', () => {
it('should make a GET call to "/saml/identityProvider"', () => {
saml.getProvider();
expect(api.get).toHaveBeenCalledTimes(1);
expect(api.get).toHaveBeenCalledWith('/rest/organizations/{organizationName}/saml/identityProvider');
});
});

describe('listRealms', () => {
it('should make a GET call to "/saml/identityProvider/realms"', () => {
saml.listRealms();
expect(api.get).toHaveBeenCalledTimes(1);
expect(api.get).toHaveBeenCalledWith('/rest/organizations/{organizationName}/saml/identityProvider/realms');
});
});

describe('deleteProvdier', () => {
it('should make a DELETE call to "/saml/identityProvider"', () => {
saml.deleteProvider();
expect(api.delete).toHaveBeenCalledTimes(1);
expect(api.delete).toHaveBeenCalledWith('/rest/organizations/{organizationName}/saml/identityProvider');
});
});

describe('create', () => {
it('should make a POST call to "/saml/identityProvider"', () => {
const provider: New<SamlIdentityProviderModel> = {
displayName: 'My SAML SSO',
entityId: 'whatever',
organizationIds: [{id: 'org-1'}, {id: 'org-2'}],
postBindingEndpoint: 'the-saml-endpoint',
x509Certificate: 'my-certificate',
};

saml.create(provider);
expect(api.post).toHaveBeenCalledTimes(1);
expect(api.post).toHaveBeenCalledWith(
'/rest/organizations/{organizationName}/saml/identityProvider',
provider
);
});
});

describe('update', () => {
it('should make a PUT call to "/saml/identityProvider"', () => {
const provider: SamlIdentityProviderModel = {
id: '123-abc',
displayName: 'My SAML SSO',
entityId: 'whatever',
organizationIds: [{id: 'org-1'}, {id: 'org-2'}],
postBindingEndpoint: 'the-saml-endpoint',
x509Certificate: 'my-certificate',
};

saml.update(provider);
expect(api.put).toHaveBeenCalledTimes(1);
expect(api.put).toHaveBeenCalledWith(
'/rest/organizations/{organizationName}/saml/identityProvider',
provider
);
});
});
});
1 change: 1 addition & 0 deletions src/resources/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ export * from './MachineLearning';
export * from './Pipelines';
export * from './Sources';
export * from './Fields';
export * from './Saml';
9 changes: 9 additions & 0 deletions src/resources/tests/PlatformResources.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import MachineLearning from '../MachineLearning/MachineLearning';
import Organization from '../Organizations/Organization';
import Pipelines from '../Pipelines/Pipelines';
import PlatformResources from '../PlatformResources';
import Saml from '../Saml/Saml';
import SecurityCache from '../SecurityCache/SecurityCache';
import Sources from '../Sources/Sources';

Expand Down Expand Up @@ -109,5 +110,13 @@ describe('PlatformResources', () => {
expect(platformResources.field).toBeDefined();
expect(platformResources.field).toBeInstanceOf(Field);
});

it('should register the saml resource on the platform instance', () => {
const platformResources = new PlatformResources();
platformResources.registerAll();

expect(platformResources.saml).toBeDefined();
expect(platformResources.saml).toBeInstanceOf(Saml);
});
});
});

0 comments on commit d6883fe

Please sign in to comment.