-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
164 additions
and
0 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
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,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`); | ||
} | ||
} |
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,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; | ||
} |
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,2 @@ | ||
export * from './Saml'; | ||
export * from './SamlInterfaces'; |
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,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 | ||
); | ||
}); | ||
}); | ||
}); |
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