forked from rancher/dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add generic OIDC provider support (rancher#11112)
* Add generic oidc provider support * Add oidc provider icon - filter genericoidc provider - update tests * Automatically set scope - disable advanced inputs initially * Update oidc login button with unique display name * Remove default scope for oidc provider * Add acrValue - move scope inputs * Clean up validation - update wording - remove rogue c&p Fix unit tests * Remove required authEndpoint input * Require authEndpoint for keycloakoidc - clean up validation
- Loading branch information
1 parent
4faf215
commit c6a56aa
Showing
10 changed files
with
324 additions
and
37 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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,137 @@ | ||
/* eslint-disable jest/no-hooks */ | ||
import { mount } from '@vue/test-utils'; | ||
import { _EDIT } from '@shell/config/query-params'; | ||
|
||
import oidc from '@shell/edit/auth/oidc.vue'; | ||
|
||
jest.mock('@shell/utils/clipboard', () => { | ||
return { copyTextToClipboard: jest.fn(() => Promise.resolve({})) }; | ||
}); | ||
|
||
const validClientId = 'rancheroidc'; | ||
const validClientSecret = 'TOkUxg0P67m1UXWNkJLHDPkUZFIKOWSq'; | ||
const validUrl = 'https://localhost:8080'; | ||
const validRealm = 'rancherrealm'; | ||
const validRancherUrl = 'https://localhost/verify-auth'; | ||
const validIssuer = 'http://localhost:8080/realms/rancherrealm'; | ||
const validAuthEndpoint = 'http://localhost:8080/realms/rancherrealm/protocol/openid-connect/auth'; | ||
const validScope = 'openid profile email'; | ||
|
||
const mockModel = { | ||
enabled: false, | ||
id: 'oidc', | ||
rancherUrl: validRancherUrl, | ||
issuer: validIssuer, | ||
authEndpoint: validAuthEndpoint, | ||
scope: validScope, | ||
clientId: validClientId, | ||
clientSecret: validClientSecret, | ||
type: 'oidcConfig', | ||
}; | ||
|
||
const mockedAuthConfigMixin = { | ||
data() { | ||
return { | ||
isEnabling: false, | ||
editConfig: false, | ||
model: { ...mockModel }, | ||
serverSetting: null, | ||
errors: [], | ||
originalModel: null, | ||
principals: [], | ||
authConfigName: 'oidc', | ||
}; | ||
}, | ||
computed: {}, | ||
methods: {} | ||
}; | ||
|
||
describe('oidc.vue', () => { | ||
let wrapper: any; | ||
const requiredSetup = () => ({ | ||
mixins: [mockedAuthConfigMixin], | ||
mocks: { | ||
$fetchState: { pending: false }, | ||
$store: { | ||
getters: { | ||
currentStore: () => 'current_store', | ||
'current_store/schemaFor': jest.fn(), | ||
'current_store/all': jest.fn(), | ||
'i18n/t': (val: string) => val, | ||
'i18n/exists': jest.fn(), | ||
}, | ||
dispatch: jest.fn() | ||
}, | ||
$route: { query: { AS: '' }, params: { id: 'oicd' } }, | ||
$router: { applyQuery: jest.fn() }, | ||
}, | ||
propsData: { | ||
value: { applicationSecret: '' }, | ||
mode: _EDIT, | ||
}, | ||
}); | ||
|
||
beforeEach(() => { | ||
wrapper = mount(oidc, { ...requiredSetup() }); | ||
}); | ||
afterEach(() => { | ||
wrapper.destroy(); | ||
}); | ||
|
||
it('have "Create" button enabled when provider is enabled and not editing config', async() => { | ||
wrapper.setData({ model: { enabled: true }, editConfig: false }); | ||
await wrapper.vm.$nextTick(); | ||
|
||
const saveButton = wrapper.find('[data-testid="form-save"]').element as HTMLInputElement; | ||
|
||
expect(saveButton.disabled).toBe(false); | ||
}); | ||
|
||
it('have "Create" button disabled when provider is disabled and editing config before fields are filled in', async() => { | ||
wrapper.setData({ model: {}, editConfig: true }); | ||
await wrapper.vm.$nextTick(); | ||
|
||
const saveButton = wrapper.find('[data-testid="form-save"]').element as HTMLInputElement; | ||
|
||
expect(saveButton.disabled).toBe(true); | ||
}); | ||
|
||
it('have "Create" button disabled when provider is disabled and editing config after required fields and scope is missing openid', async() => { | ||
wrapper.setData({ oidcUrls: { url: validUrl, realm: validRealm } }); | ||
await wrapper.vm.$nextTick(); | ||
|
||
const saveButton = wrapper.find('[data-testid="form-save"]').element as HTMLInputElement; | ||
|
||
expect(saveButton.disabled).toBe(true); | ||
}); | ||
|
||
it('have "Create" button enabled when customEndpoint is disabled and required fields are filled in', async() => { | ||
wrapper.setData({ oidcUrls: { url: validUrl, realm: validRealm }, oidcScope: validScope.split(' ') }); | ||
await wrapper.vm.$nextTick(); | ||
|
||
const saveButton = wrapper.find('[data-testid="form-save"]').element as HTMLInputElement; | ||
|
||
expect(saveButton.disabled).toBe(false); | ||
}); | ||
|
||
it('have "Create" button enabled when customEndpoint is enabled and required fields are filled in', async() => { | ||
wrapper.setData({ customEndpoint: { value: true }, oidcScope: validScope.split(' ') }); | ||
await wrapper.vm.$nextTick(); | ||
|
||
const saveButton = wrapper.find('[data-testid="form-save"]').element as HTMLInputElement; | ||
|
||
expect(saveButton.disabled).toBe(false); | ||
}); | ||
|
||
it('updates issuer endpoint when oidcUrls.url and oidcUrls.realm changes', async() => { | ||
wrapper.setData({ oidcUrls: { url: validUrl } }); | ||
await wrapper.vm.$nextTick(); | ||
|
||
expect(wrapper.vm.model.issuer).toBe(`${ validUrl }/realms/`); | ||
|
||
wrapper.setData({ oidcUrls: { realm: validRealm } }); | ||
await wrapper.vm.$nextTick(); | ||
|
||
expect(wrapper.vm.model.issuer).toBe(`${ validUrl }/realms/${ validRealm }`); | ||
}); | ||
}); |
Oops, something went wrong.