@api-client/ui 0.5.39 → 0.5.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/tsconfig.tsbuildinfo +1 -0
- package/package.json +1 -1
- package/.aiexclude +0 -3
- package/.cursor/rules/html-and-css-best-practices.mdc +0 -63
- package/.cursor/rules/lit-best-practices.mdc +0 -89
- package/.editorconfig +0 -29
- package/.github/CONTRIBUTING.md +0 -24
- package/.github/instructions/html-and-css-best-practices.instructions.md +0 -70
- package/.github/instructions/lit-best-practices.instructions.md +0 -90
- package/.github/release.yml +0 -14
- package/.github/stale.yml +0 -23
- package/.github/workflows/auto-release.yml +0 -182
- package/.github/workflows/release.yml +0 -82
- package/.prettierrc.js +0 -14
- package/.vscode/settings.json +0 -18
- package/RELEASE.md +0 -163
- package/RELEASE_SETUP.md +0 -235
- package/build/src/demo/DemoPage.d.ts +0 -81
- package/build/src/demo/DemoPage.d.ts.map +0 -1
- package/build/src/demo/DemoPage.js +0 -175
- package/build/src/demo/DemoPage.js.map +0 -1
- package/build/src/demo/DemoStyles.d.ts +0 -3
- package/build/src/demo/DemoStyles.d.ts.map +0 -1
- package/build/src/demo/DemoStyles.js +0 -60
- package/build/src/demo/DemoStyles.js.map +0 -1
- package/build/test/elements/navigation/Navigation.test.d.ts +0 -3
- package/build/test/elements/navigation/Navigation.test.d.ts.map +0 -1
- package/build/test/elements/navigation/Navigation.test.js +0 -113
- package/build/test/elements/navigation/Navigation.test.js.map +0 -1
- package/commitlint.config.cjs +0 -2
- package/demo/elements/authorization/AuthPlugin.js +0 -57
- package/demo/elements/authorization/AuthProxy.js +0 -215
- package/demo/elements/authorization/api-key.html +0 -27
- package/demo/elements/authorization/api-key.ts +0 -44
- package/demo/elements/authorization/basic.html +0 -27
- package/demo/elements/authorization/basic.ts +0 -43
- package/demo/elements/authorization/bearer.html +0 -27
- package/demo/elements/authorization/bearer.ts +0 -43
- package/demo/elements/authorization/env.js +0 -8
- package/demo/elements/authorization/index.html +0 -44
- package/demo/elements/authorization/ntlm.html +0 -27
- package/demo/elements/authorization/ntlm.ts +0 -43
- package/demo/elements/authorization/oauth-authorize.html +0 -75
- package/demo/elements/authorization/oauth-authorize.ts +0 -40
- package/demo/elements/authorization/oauth-error.html +0 -18
- package/demo/elements/authorization/oauth-error.ts +0 -10
- package/demo/elements/authorization/oauth-popup.html +0 -36
- package/demo/elements/authorization/oauth2.html +0 -27
- package/demo/elements/authorization/oauth2.ts +0 -100
- package/demo/elements/authorization/oidc.html +0 -27
- package/demo/elements/authorization/oidc.ts +0 -139
- package/demo/elements/authorization/private.crt +0 -31
- package/demo/elements/authorization/private.csr +0 -28
- package/demo/elements/authorization/private.key +0 -51
- package/demo/elements/authorization/private.pem +0 -31
- package/demo/elements/authorization/redirect.html +0 -20
- package/demo/elements/authorization/ssl-commands.sh +0 -30
- package/demo/elements/authorization/ssl.conf +0 -24
- package/demo/elements/autocomplete/index.html +0 -64
- package/demo/elements/autocomplete/index.ts +0 -171
- package/demo/elements/code-editor/CodeEditorDemo.ts +0 -173
- package/demo/elements/code-editor/index.html +0 -19
- package/demo/elements/context-menu/DemoIcons.ts +0 -21
- package/demo/elements/context-menu/basic.html +0 -25
- package/demo/elements/context-menu/basic.ts +0 -119
- package/demo/elements/context-menu/custom-data.html +0 -25
- package/demo/elements/context-menu/custom-data.ts +0 -62
- package/demo/elements/context-menu/demo.css +0 -28
- package/demo/elements/context-menu/enabled-state.html +0 -25
- package/demo/elements/context-menu/enabled-state.ts +0 -73
- package/demo/elements/context-menu/icons.html +0 -25
- package/demo/elements/context-menu/icons.ts +0 -64
- package/demo/elements/context-menu/index.html +0 -43
- package/demo/elements/context-menu/nested.html +0 -25
- package/demo/elements/context-menu/nestedt.ts +0 -152
- package/demo/elements/context-menu/no-execute.html +0 -25
- package/demo/elements/context-menu/no-execute.ts +0 -134
- package/demo/elements/context-menu/radio-menu.html +0 -25
- package/demo/elements/context-menu/radio-menu.ts +0 -83
- package/demo/elements/context-menu/separators.html +0 -25
- package/demo/elements/context-menu/separators.ts +0 -172
- package/demo/elements/currency/index.html +0 -91
- package/demo/elements/currency/index.ts +0 -352
- package/demo/elements/environment/environment-editor.html +0 -20
- package/demo/elements/environment/environment-editor.ts +0 -49
- package/demo/elements/environment/index.html +0 -33
- package/demo/elements/environment/server-editor.html +0 -20
- package/demo/elements/environment/server-editor.ts +0 -67
- package/demo/elements/environment/variables-editor.html +0 -20
- package/demo/elements/environment/variables-editor.ts +0 -94
- package/demo/elements/har/har-viewer.html +0 -20
- package/demo/elements/har/har-viewer.ts +0 -76
- package/demo/elements/har/har1.har +0 -3044
- package/demo/elements/har/har2.json +0 -439
- package/demo/elements/har/index.html +0 -26
- package/demo/elements/highlight/example.md +0 -27
- package/demo/elements/highlight/index.html +0 -31
- package/demo/elements/highlight/marked-highlight.html +0 -132
- package/demo/elements/highlight/marked-highlight.ts +0 -22
- package/demo/elements/highlight/prism-highlight.html +0 -62
- package/demo/elements/highlight/prism-highlight.ts +0 -17
- package/demo/elements/http/body-editor.html +0 -17
- package/demo/elements/http/body-editor.ts +0 -115
- package/demo/elements/http/headers.html +0 -17
- package/demo/elements/http/headers.ts +0 -59
- package/demo/elements/http/http-assertions.html +0 -20
- package/demo/elements/http/http-assertions.ts +0 -89
- package/demo/elements/http/http-flows.html +0 -23
- package/demo/elements/http/http-flows.ts +0 -89
- package/demo/elements/http/index.html +0 -45
- package/demo/elements/http/request-editor.html +0 -26
- package/demo/elements/http/request-editor.ts +0 -197
- package/demo/elements/http/request-log.html +0 -16
- package/demo/elements/http/request-log.ts +0 -136
- package/demo/elements/http/url-editing.html +0 -17
- package/demo/elements/http/url-editing.ts +0 -112
- package/demo/elements/icons/index.html +0 -81
- package/demo/elements/icons/index.ts +0 -52
- package/demo/elements/index.html +0 -72
- package/demo/elements/mention-textarea/index.html +0 -19
- package/demo/elements/mention-textarea/index.ts +0 -205
- package/demo/elements/navigation/navigation-item.html +0 -49
- package/demo/elements/navigation/navigation-item.ts +0 -131
- package/demo/elements/navigation/navigation.html +0 -20
- package/demo/elements/navigation/navigation.ts +0 -45
- package/demo/elements/project/index.html +0 -29
- package/demo/elements/project/project-run-report.html +0 -20
- package/demo/elements/project/project-run-report.ts +0 -132
- package/demo/elements/project/request-editor.html +0 -23
- package/demo/elements/project/request-editor.ts +0 -232
- package/demo/elements/user/user-avatar.html +0 -17
- package/demo/elements/user/user-avatar.ts +0 -60
- package/demo/env.js +0 -4
- package/demo/index.html +0 -34
- package/demo/layout/index.html +0 -94
- package/demo/layout/index.ts +0 -190
- package/demo/md/DemoStyles.ts +0 -61
- package/demo/md/UiDemoPage.ts +0 -6
- package/demo/md/buttons/button.html +0 -121
- package/demo/md/buttons/button.ts +0 -246
- package/demo/md/buttons/group.html +0 -36
- package/demo/md/buttons/group.ts +0 -171
- package/demo/md/checkbox/index.html +0 -39
- package/demo/md/checkbox/index.ts +0 -220
- package/demo/md/chip/chip.html +0 -70
- package/demo/md/chip/chip.ts +0 -219
- package/demo/md/chip/pawel6c9a.jpg +0 -0
- package/demo/md/collapse/CustomDetail.ts +0 -89
- package/demo/md/collapse/collapse.html +0 -21
- package/demo/md/collapse/collapse.ts +0 -78
- package/demo/md/date-picker/date-picker.ts +0 -336
- package/demo/md/date-picker/index.html +0 -171
- package/demo/md/dialog/confirm-dialog.html +0 -49
- package/demo/md/dialog/confirm-dialog.ts +0 -121
- package/demo/md/dialog/dialog.html +0 -25
- package/demo/md/dialog/dialog.ts +0 -468
- package/demo/md/dropdown-list/index.html +0 -31
- package/demo/md/dropdown-list/index.ts +0 -158
- package/demo/md/icon-button/index.html +0 -122
- package/demo/md/icon-button/index.ts +0 -132
- package/demo/md/index.html +0 -73
- package/demo/md/inputs/input.html +0 -73
- package/demo/md/inputs/input.ts +0 -278
- package/demo/md/inputs/radio.html +0 -39
- package/demo/md/inputs/radio.ts +0 -156
- package/demo/md/inputs/switch.html +0 -45
- package/demo/md/inputs/switch.ts +0 -144
- package/demo/md/list/list.html +0 -65
- package/demo/md/list/list.ts +0 -204
- package/demo/md/listbox/listbox.html +0 -31
- package/demo/md/listbox/listbox.ts +0 -27
- package/demo/md/menu/index.html +0 -19
- package/demo/md/menu/index.ts +0 -514
- package/demo/md/notification/snack.html +0 -21
- package/demo/md/notification/snack.ts +0 -70
- package/demo/md/progress/progress.html +0 -46
- package/demo/md/progress/progress.ts +0 -161
- package/demo/md/segmented-button/index.html +0 -21
- package/demo/md/segmented-button/index.ts +0 -55
- package/demo/md/select/index.html +0 -16
- package/demo/md/select/index.ts +0 -217
- package/demo/md/tabs/tabs.html +0 -40
- package/demo/md/tabs/tabs.ts +0 -214
- package/demo/oauth-popup.html +0 -36
- package/demo/page.css +0 -8
- package/demo/resources/calendar-month.png +0 -0
- package/demo/resources/favorite.png +0 -0
- package/demo/resources/fingerprint.png +0 -0
- package/demo/resources/home-work.png +0 -0
- package/demo/resources/mood.png +0 -0
- package/demo/resources/print.png +0 -0
- package/demo/resources/stars.png +0 -0
- package/demo/resources/theaters.png +0 -0
- package/demo/tsconfig.json +0 -4
- package/eslint.config.js +0 -97
- package/scripts/copy-assets.js +0 -21
- package/scripts/release.js +0 -66
- package/src/demo/DemoPage.ts +0 -169
- package/src/demo/DemoStyles.ts +0 -60
- package/test/README.md +0 -375
- package/test/contextual-menu/ContextMenu.test.ts +0 -760
- package/test/contextual-menu/ContextMenuElement.test.ts +0 -569
- package/test/core/activity.spec.ts +0 -413
- package/test/core/activity_manager.spec.ts +0 -544
- package/test/core/application.spec.ts +0 -218
- package/test/core/fragment.spec.ts +0 -565
- package/test/core/fragment_manager.spec.ts +0 -404
- package/test/core/live_data.spec.ts +0 -558
- package/test/core/renderer.spec.ts +0 -113
- package/test/dom-assertions.test.ts +0 -182
- package/test/elements/MonacoSetup.ts +0 -65
- package/test/elements/authorization/basic-method.test.ts +0 -177
- package/test/elements/authorization/bearer-method.test.ts +0 -143
- package/test/elements/authorization/ntlm-method.test.ts +0 -219
- package/test/elements/authorization/oauth2-client-credentials-method.test.ts +0 -334
- package/test/elements/authorization/oauth2-code-method.test.ts +0 -320
- package/test/elements/authorization/oauth2-custom-grant-method.test.ts +0 -255
- package/test/elements/authorization/oauth2-device-code-method.test.ts +0 -371
- package/test/elements/authorization/oauth2-implicit-method.test.ts +0 -407
- package/test/elements/authorization/oauth2-jwt-method.test.ts +0 -217
- package/test/elements/authorization/oauth2-password-method.test.ts +0 -275
- package/test/elements/authorization/openid-method.test.ts +0 -591
- package/test/elements/autocomplete/autocomplete-input.spec.ts +0 -646
- package/test/elements/code-editor/code-editor.accessibility.test.ts +0 -298
- package/test/elements/code-editor/code-editor.test.ts +0 -574
- package/test/elements/currency/CurrencyPicker.accessibility.test.ts +0 -328
- package/test/elements/currency/CurrencyPicker.core.test.ts +0 -318
- package/test/elements/currency/CurrencyPicker.integration.test.ts +0 -482
- package/test/elements/currency/CurrencyPicker.test.ts +0 -486
- package/test/elements/data-table/DataTable.browser.test.ts +0 -649
- package/test/elements/har/HarUtils.test.ts +0 -45
- package/test/elements/har/HarViewerElement.test.ts +0 -687
- package/test/elements/har/test-data/har1.har +0 -3044
- package/test/elements/highlight/MarkedHighlightElement.test.ts +0 -452
- package/test/elements/highlight/PrismHighlightElement.test.ts +0 -79
- package/test/elements/highlight/PrismHighlighter.test.ts +0 -94
- package/test/elements/highlight/remoteSanitization.md +0 -1
- package/test/elements/highlight/test.md +0 -3
- package/test/elements/highlight/test1.md +0 -3
- package/test/elements/highlight/test2.md +0 -1
- package/test/elements/http/BodyFormdataEditorElement.test.ts +0 -482
- package/test/elements/http/BodyMultipartEditorElement.test.ts +0 -658
- package/test/elements/http/BodyRawEditorElement.test.ts +0 -90
- package/test/elements/http/CertificateAdd.test.ts +0 -457
- package/test/elements/http/HttpAssertions.test.ts +0 -994
- package/test/elements/http/HttpFlows.test.ts +0 -502
- package/test/elements/http/UrlEncodeUtils.test.ts +0 -202
- package/test/elements/layout/SplitItem.test.ts +0 -440
- package/test/elements/layout/SplitLayoutManager.test.ts +0 -1501
- package/test/elements/layout/SplitPanel.test.ts +0 -1109
- package/test/elements/mention-textarea/MentionTextArea.basic.test.ts +0 -114
- package/test/elements/mention-textarea/MentionTextArea.test.ts +0 -613
- package/test/elements/navigation/Navigation.test.ts +0 -120
- package/test/env.ts +0 -15
- package/test/events/EventTypes.test.ts +0 -363
- package/test/events/EventsTestHelpers.ts +0 -16
- package/test/helpers/TestUtils.ts +0 -243
- package/test/helpers/UiMock.ts +0 -185
- package/test/lib/Dom.test.ts +0 -231
- package/test/md/button/UiButton.test.ts +0 -347
- package/test/md/button/UiIconButton.test.ts +0 -155
- package/test/md/chip/UiChip.test.ts +0 -219
- package/test/md/collapse/UiCollapse.test.ts +0 -250
- package/test/md/collapse/flex-layout.test.ts +0 -105
- package/test/md/date-time/DateTime.test.ts +0 -348
- package/test/md/dialog/UiConfirmDialog.test.ts +0 -131
- package/test/md/dialog/UiDialog.test.ts +0 -759
- package/test/md/menu/Menu.test.ts +0 -855
- package/test/md/menu/MenuIntegration.test.ts +0 -426
- package/test/md/menu/MenuItem.test.ts +0 -652
- package/test/md/menu/SubMenu.test.ts +0 -410
- package/test/md/progress/UiCircularProgressElement.test.ts +0 -481
- package/test/md/progress/UiProgressElement.test.ts +0 -117
- package/test/md/progress/UiRangeElement.test.ts +0 -156
- package/test/md/select/Select.test.ts +0 -925
- package/test/plugins/takeScreenshotPlugin.js +0 -35
- package/test/setup.test.ts +0 -217
- package/test/setup.ts +0 -117
- package/test/tsconfig.json +0 -7
- package/web-dev-server.config.js +0 -21
- package/web-test-runner.config.js +0 -90
|
@@ -1,591 +0,0 @@
|
|
|
1
|
-
import { html, fixture, assert } from '@open-wc/testing'
|
|
2
|
-
import sinon from 'sinon'
|
|
3
|
-
import {
|
|
4
|
-
ContextEvent,
|
|
5
|
-
EventTypes,
|
|
6
|
-
IOidcAuthorization,
|
|
7
|
-
IOpenIdProviderMetadata,
|
|
8
|
-
IRequestAuthorization,
|
|
9
|
-
RequestAuthorizationKind,
|
|
10
|
-
OidcAuthorization as OidcAuthorizationFactory,
|
|
11
|
-
IOidcTokenInfo,
|
|
12
|
-
IOidcTokenError,
|
|
13
|
-
} from '@api-client/core/browser.js'
|
|
14
|
-
import env from '../../env.js'
|
|
15
|
-
import OidcAuthorization, {
|
|
16
|
-
defaultGrantTypes,
|
|
17
|
-
discoveryCache,
|
|
18
|
-
} from '../../../src/elements/authorization/ui/OidcAuthorization.js'
|
|
19
|
-
import type UiButton from '../../../src/md/button/internals/button.js'
|
|
20
|
-
import type Input from '../../../src/md/input/Input.js'
|
|
21
|
-
import '../../../src/define/authorization/oidc-authorization.js'
|
|
22
|
-
|
|
23
|
-
describe('Authorization', () => {
|
|
24
|
-
describe('<oidc-authorization>', () => {
|
|
25
|
-
const baseConfig: IOidcAuthorization = {
|
|
26
|
-
redirectUri: `${window.location.origin}/demo/oauth-popup.html`,
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
async function basicFixture(opts: IOidcAuthorization): Promise<OidcAuthorization> {
|
|
30
|
-
const auth: IRequestAuthorization = {
|
|
31
|
-
config: opts,
|
|
32
|
-
enabled: true,
|
|
33
|
-
kind: RequestAuthorizationKind,
|
|
34
|
-
type: 'open id',
|
|
35
|
-
valid: true,
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return fixture(html`<oidc-authorization .authorization="${auth}"></oidc-authorization>`)
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const oidcConfig: Readonly<IOpenIdProviderMetadata> = Object.freeze({
|
|
42
|
-
issuer: 'http://localhost:8004',
|
|
43
|
-
token_endpoint: 'http://localhost:8004/token',
|
|
44
|
-
authorization_endpoint: 'http://localhost:8004/authorize',
|
|
45
|
-
userinfo_endpoint: 'http://localhost:8004/userinfo',
|
|
46
|
-
token_endpoint_auth_methods_supported: ['none'],
|
|
47
|
-
jwks_uri: 'http://localhost:8004/jwks',
|
|
48
|
-
response_types_supported: ['code', 'id_token', 'code id_token'],
|
|
49
|
-
grant_types_supported: ['authorization_code', 'custom'],
|
|
50
|
-
token_endpoint_auth_signing_alg_values_supported: ['RS256'],
|
|
51
|
-
response_modes_supported: ['query'],
|
|
52
|
-
id_token_signing_alg_values_supported: ['RS256'],
|
|
53
|
-
revocation_endpoint: 'http://localhost:8004/revoke',
|
|
54
|
-
subject_types_supported: ['public'],
|
|
55
|
-
scopes_supported: ['openid', 'profile'],
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
describe('base state', () => {
|
|
59
|
-
it('renders base state component', async () => {
|
|
60
|
-
const element = await basicFixture({ ...baseConfig })
|
|
61
|
-
const issuer = element.shadowRoot!.querySelector('[name="issuerUri"]')
|
|
62
|
-
assert.ok(issuer, 'has the issuer URI input')
|
|
63
|
-
|
|
64
|
-
const allFields = element.shadowRoot!.querySelectorAll('[name]')
|
|
65
|
-
assert.lengthOf(allFields, 1, 'has only one input field')
|
|
66
|
-
})
|
|
67
|
-
|
|
68
|
-
it('has the request tokens button disabled', async () => {
|
|
69
|
-
const element = await basicFixture({ ...baseConfig })
|
|
70
|
-
const button = element.shadowRoot!.querySelector('[data-type="get-token"]') as UiButton
|
|
71
|
-
assert.ok(button, 'has the button')
|
|
72
|
-
assert.isTrue(button.disabled, 'the button is disabled')
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
it('has the read button', async () => {
|
|
76
|
-
const element = await basicFixture({ ...baseConfig })
|
|
77
|
-
const button = element.shadowRoot!.querySelector('[data-type="read-discovery"]') as UiButton
|
|
78
|
-
assert.ok(button, 'has the button')
|
|
79
|
-
assert.notOk(button.disabled, 'the button is not disabled')
|
|
80
|
-
})
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
describe('requesting the discovery data', () => {
|
|
84
|
-
const fullDiscoveryUrl = `${env.oauth2.issuer}/.well-known/openid-configuration`
|
|
85
|
-
let element: OidcAuthorization
|
|
86
|
-
|
|
87
|
-
beforeEach(async () => {
|
|
88
|
-
discoveryCache.clear()
|
|
89
|
-
element = await basicFixture({
|
|
90
|
-
...baseConfig,
|
|
91
|
-
issuerUri: env.oauth2.issuer,
|
|
92
|
-
})
|
|
93
|
-
})
|
|
94
|
-
|
|
95
|
-
it('processes the data', async () => {
|
|
96
|
-
await element.discover()
|
|
97
|
-
assert.equal(element.config.authorizationUri, `${env.oauth2.issuer}/authorize`, 'sets the authorizationUri')
|
|
98
|
-
assert.equal(element.config.accessTokenUri, `${env.oauth2.issuer}/token`, 'sets the accessTokenUri')
|
|
99
|
-
// the rest is in unit tests
|
|
100
|
-
})
|
|
101
|
-
|
|
102
|
-
it('sets the discovered flag', async () => {
|
|
103
|
-
await element.discover()
|
|
104
|
-
assert.isTrue(element.discovered)
|
|
105
|
-
})
|
|
106
|
-
|
|
107
|
-
it('sets the message and flags when error', async () => {
|
|
108
|
-
element.config.issuerUri = 'http://localhost:1234/notinhg'
|
|
109
|
-
element.requestUpdate()
|
|
110
|
-
await element.updateComplete
|
|
111
|
-
await element.discover()
|
|
112
|
-
assert.isFalse(element.discovered, 'discovered is false')
|
|
113
|
-
assert.equal(element.lastErrorMessage, 'Unable to read the discovery information.', 'lastErrorMessage is set')
|
|
114
|
-
})
|
|
115
|
-
|
|
116
|
-
it('sets the cache data', async () => {
|
|
117
|
-
await element.discover()
|
|
118
|
-
assert.ok(discoveryCache.get(fullDiscoveryUrl))
|
|
119
|
-
})
|
|
120
|
-
|
|
121
|
-
it('reuses the cached data', async () => {
|
|
122
|
-
const spy = sinon.spy(window, 'fetch')
|
|
123
|
-
try {
|
|
124
|
-
await element.discover()
|
|
125
|
-
await element.discover()
|
|
126
|
-
} finally {
|
|
127
|
-
spy.restore()
|
|
128
|
-
}
|
|
129
|
-
assert.isTrue(spy.calledOnce)
|
|
130
|
-
})
|
|
131
|
-
|
|
132
|
-
it('throws when no issuerUrl', async () => {
|
|
133
|
-
let message: string | undefined
|
|
134
|
-
element.config.issuerUri = undefined
|
|
135
|
-
element.requestUpdate()
|
|
136
|
-
await element.updateComplete
|
|
137
|
-
try {
|
|
138
|
-
await element.discover()
|
|
139
|
-
} catch (e) {
|
|
140
|
-
message = (e as Error).message
|
|
141
|
-
}
|
|
142
|
-
assert.equal(message, 'Set the issuer URI first.', 'throws the error')
|
|
143
|
-
assert.equal(element.lastErrorMessage, 'Set the issuer URI first.', 'sets the error message')
|
|
144
|
-
})
|
|
145
|
-
|
|
146
|
-
it('reads the data after the read button click', async () => {
|
|
147
|
-
const spy = sinon.spy(element, 'discover')
|
|
148
|
-
const button = element.shadowRoot!.querySelector('[data-type="read-discovery"]') as UiButton
|
|
149
|
-
button.click()
|
|
150
|
-
assert.isTrue(spy.calledOnce)
|
|
151
|
-
})
|
|
152
|
-
})
|
|
153
|
-
|
|
154
|
-
describe('propagateOidc()', () => {
|
|
155
|
-
let element: OidcAuthorization
|
|
156
|
-
|
|
157
|
-
beforeEach(async () => {
|
|
158
|
-
element = await basicFixture({
|
|
159
|
-
...baseConfig,
|
|
160
|
-
issuerUri: env.oauth2.issuer,
|
|
161
|
-
})
|
|
162
|
-
})
|
|
163
|
-
|
|
164
|
-
it('sets the authorizationUri', () => {
|
|
165
|
-
element.propagateOidc({ ...oidcConfig })
|
|
166
|
-
assert.equal(element.config.authorizationUri, oidcConfig.authorization_endpoint, 'authorizationUri is set')
|
|
167
|
-
})
|
|
168
|
-
|
|
169
|
-
it('sets the accessTokenUri', () => {
|
|
170
|
-
element.propagateOidc({ ...oidcConfig })
|
|
171
|
-
assert.equal(element.config.accessTokenUri, oidcConfig.token_endpoint, 'accessTokenUri is set')
|
|
172
|
-
})
|
|
173
|
-
|
|
174
|
-
it('ignores accessTokenUri when not set', () => {
|
|
175
|
-
element.propagateOidc({ ...oidcConfig, token_endpoint: undefined })
|
|
176
|
-
assert.isUndefined(element.config.accessTokenUri, 'accessTokenUri is not set')
|
|
177
|
-
})
|
|
178
|
-
|
|
179
|
-
it('sets the grantTypes', () => {
|
|
180
|
-
element.propagateOidc({ ...oidcConfig })
|
|
181
|
-
assert.typeOf(element.grantTypes, 'array', 'grantTypes is an array')
|
|
182
|
-
assert.lengthOf(element.grantTypes!, oidcConfig.grant_types_supported!.length, 'has all types')
|
|
183
|
-
const [g1, g2] = element.grantTypes!
|
|
184
|
-
assert.equal(g1.type, 'authorization_code', 'grant #1 type is set')
|
|
185
|
-
assert.equal(g1.label, 'Authorization code', 'grant #1 label is set')
|
|
186
|
-
assert.equal(g2.type, 'custom', 'grant #2 type is set')
|
|
187
|
-
assert.equal(g2.label, 'custom', 'grant #2 label is set')
|
|
188
|
-
})
|
|
189
|
-
|
|
190
|
-
it('sets the default grantTypes', () => {
|
|
191
|
-
element.propagateOidc({ ...oidcConfig, grant_types_supported: undefined })
|
|
192
|
-
assert.deepEqual(element.grantTypes, defaultGrantTypes)
|
|
193
|
-
})
|
|
194
|
-
|
|
195
|
-
it('sets the scopes', () => {
|
|
196
|
-
element.propagateOidc({ ...oidcConfig })
|
|
197
|
-
assert.typeOf(element.config.scopes, 'array', 'scopes is an array')
|
|
198
|
-
assert.deepEqual(element.config.scopes, ['openid', 'profile'], 'has the scopes')
|
|
199
|
-
})
|
|
200
|
-
|
|
201
|
-
it('sets the default scopes', () => {
|
|
202
|
-
element.propagateOidc({ ...oidcConfig, scopes_supported: undefined })
|
|
203
|
-
assert.deepEqual(element.config.scopes, ['openid'])
|
|
204
|
-
})
|
|
205
|
-
|
|
206
|
-
it('sets the supportedResponses', () => {
|
|
207
|
-
element.propagateOidc({ ...oidcConfig })
|
|
208
|
-
assert.typeOf(element.config.supportedResponses, 'array', 'supportedResponses is an array')
|
|
209
|
-
assert.lengthOf(element.config.supportedResponses!, 3, 'has all supportedResponses')
|
|
210
|
-
const [r1, r2, r3] = element.config.supportedResponses!
|
|
211
|
-
assert.isArray(r1, 'response #1 is an array')
|
|
212
|
-
assert.lengthOf(r1, 1, 'response #1 has a single type')
|
|
213
|
-
assert.equal(r1[0].type, 'code', 'response #1 has type type')
|
|
214
|
-
assert.equal(r1[0].label, 'Code', 'response #1 has type label')
|
|
215
|
-
assert.lengthOf(r2, 1, 'response #2 has a single type')
|
|
216
|
-
assert.equal(r2[0].type, 'id_token', 'response #2 has type type')
|
|
217
|
-
assert.equal(r2[0].label, 'ID token', 'response #2 has type label')
|
|
218
|
-
assert.lengthOf(r3, 2, 'response #3 has a 2 types')
|
|
219
|
-
assert.equal(r3[0].type, 'code', 'response #3,1 has type type')
|
|
220
|
-
assert.equal(r3[0].label, 'Code', 'response #3,1 has type label')
|
|
221
|
-
assert.equal(r3[1].type, 'id_token', 'response #3,2 has type type')
|
|
222
|
-
assert.equal(r3[1].label, 'ID token', 'response #3,2 has type label')
|
|
223
|
-
})
|
|
224
|
-
})
|
|
225
|
-
|
|
226
|
-
describe('Discovered UI', () => {
|
|
227
|
-
let element: OidcAuthorization
|
|
228
|
-
|
|
229
|
-
beforeEach(async () => {
|
|
230
|
-
element = await basicFixture({
|
|
231
|
-
...baseConfig,
|
|
232
|
-
issuerUri: env.oauth2.issuer,
|
|
233
|
-
clientId: 'test-cid',
|
|
234
|
-
clientSecret: 'test-secret',
|
|
235
|
-
grantType: 'authorization_code',
|
|
236
|
-
})
|
|
237
|
-
await element.discover()
|
|
238
|
-
})
|
|
239
|
-
|
|
240
|
-
it('has the response type input', () => {
|
|
241
|
-
const node = element.shadowRoot!.querySelector('[name="responseType"')
|
|
242
|
-
assert.ok(node)
|
|
243
|
-
})
|
|
244
|
-
|
|
245
|
-
it('has the grant type input', () => {
|
|
246
|
-
const node = element.shadowRoot!.querySelector('[name="grantType"')
|
|
247
|
-
assert.ok(node)
|
|
248
|
-
})
|
|
249
|
-
|
|
250
|
-
it('has the clientId input', () => {
|
|
251
|
-
const node = element.shadowRoot!.querySelector('[name="clientId"') as Input
|
|
252
|
-
assert.ok(node, 'has the input')
|
|
253
|
-
assert.isTrue(node.required, 'is required')
|
|
254
|
-
})
|
|
255
|
-
|
|
256
|
-
it('has the clientSecret input', () => {
|
|
257
|
-
const node = element.shadowRoot!.querySelector('[name="clientSecret"') as Input
|
|
258
|
-
assert.ok(node, 'has the input')
|
|
259
|
-
assert.isTrue(node.required, 'is required')
|
|
260
|
-
})
|
|
261
|
-
})
|
|
262
|
-
|
|
263
|
-
describe('Data change and propagation', () => {
|
|
264
|
-
let element: OidcAuthorization
|
|
265
|
-
beforeEach(async () => {
|
|
266
|
-
element = await basicFixture({
|
|
267
|
-
...baseConfig,
|
|
268
|
-
issuerUri: env.oauth2.issuer,
|
|
269
|
-
clientId: 'test-cid',
|
|
270
|
-
clientSecret: 'test-secret',
|
|
271
|
-
grantType: 'authorization_code',
|
|
272
|
-
})
|
|
273
|
-
await element.discover()
|
|
274
|
-
})
|
|
275
|
-
|
|
276
|
-
it('propagates issuerUri change', async () => {
|
|
277
|
-
const spy = sinon.spy()
|
|
278
|
-
element.addEventListener('change', spy)
|
|
279
|
-
const input = element.shadowRoot!.querySelector('[name="issuerUri"') as Input
|
|
280
|
-
input.value = 'https://api.domain.com'
|
|
281
|
-
input.dispatchEvent(new Event('change'))
|
|
282
|
-
assert.equal(element.config.issuerUri, 'https://api.domain.com', 'propagates the change')
|
|
283
|
-
assert.isTrue(spy.calledOnce, 'dispatched the change event')
|
|
284
|
-
})
|
|
285
|
-
})
|
|
286
|
-
|
|
287
|
-
describe('readTokenValue()', () => {
|
|
288
|
-
let element: OidcAuthorization
|
|
289
|
-
|
|
290
|
-
beforeEach(async () => {
|
|
291
|
-
element = await basicFixture({
|
|
292
|
-
...baseConfig,
|
|
293
|
-
issuerUri: env.oauth2.issuer,
|
|
294
|
-
})
|
|
295
|
-
})
|
|
296
|
-
|
|
297
|
-
it('returns the token for token response type', () => {
|
|
298
|
-
const result = element.readTokenValue({
|
|
299
|
-
responseType: 'token',
|
|
300
|
-
state: '',
|
|
301
|
-
time: 1,
|
|
302
|
-
accessToken: 'test-token',
|
|
303
|
-
})
|
|
304
|
-
assert.equal(result, 'test-token')
|
|
305
|
-
})
|
|
306
|
-
|
|
307
|
-
it('returns the token for code response type', () => {
|
|
308
|
-
const result = element.readTokenValue({
|
|
309
|
-
responseType: 'code',
|
|
310
|
-
state: '',
|
|
311
|
-
time: 1,
|
|
312
|
-
accessToken: 'test-token',
|
|
313
|
-
})
|
|
314
|
-
assert.equal(result, 'test-token')
|
|
315
|
-
})
|
|
316
|
-
|
|
317
|
-
it('returns the token for id_token response type', () => {
|
|
318
|
-
const result = element.readTokenValue({
|
|
319
|
-
responseType: 'id_token',
|
|
320
|
-
state: '',
|
|
321
|
-
time: 1,
|
|
322
|
-
idToken: 'test-token',
|
|
323
|
-
})
|
|
324
|
-
assert.equal(result, 'test-token')
|
|
325
|
-
})
|
|
326
|
-
|
|
327
|
-
it('returns the token for id response type', () => {
|
|
328
|
-
const result = element.readTokenValue({
|
|
329
|
-
responseType: 'id',
|
|
330
|
-
state: '',
|
|
331
|
-
time: 1,
|
|
332
|
-
idToken: 'test-token',
|
|
333
|
-
})
|
|
334
|
-
assert.equal(result, 'test-token')
|
|
335
|
-
})
|
|
336
|
-
|
|
337
|
-
it('returns the token from accessToken', () => {
|
|
338
|
-
const result = element.readTokenValue({
|
|
339
|
-
responseType: 'other',
|
|
340
|
-
state: '',
|
|
341
|
-
time: 1,
|
|
342
|
-
accessToken: 'test-token',
|
|
343
|
-
})
|
|
344
|
-
assert.equal(result, 'test-token')
|
|
345
|
-
})
|
|
346
|
-
|
|
347
|
-
it('returns the token from refreshToken', () => {
|
|
348
|
-
const result = element.readTokenValue({
|
|
349
|
-
responseType: 'other',
|
|
350
|
-
state: '',
|
|
351
|
-
time: 1,
|
|
352
|
-
refreshToken: 'test-token',
|
|
353
|
-
})
|
|
354
|
-
assert.equal(result, 'test-token')
|
|
355
|
-
})
|
|
356
|
-
|
|
357
|
-
it('returns the token from idToken', () => {
|
|
358
|
-
const result = element.readTokenValue({
|
|
359
|
-
responseType: 'other',
|
|
360
|
-
state: '',
|
|
361
|
-
time: 1,
|
|
362
|
-
idToken: 'test-token',
|
|
363
|
-
})
|
|
364
|
-
assert.equal(result, 'test-token')
|
|
365
|
-
})
|
|
366
|
-
|
|
367
|
-
it('returns the empty string for default', () => {
|
|
368
|
-
const result = element.readTokenValue({
|
|
369
|
-
responseType: 'other',
|
|
370
|
-
state: '',
|
|
371
|
-
time: 1,
|
|
372
|
-
})
|
|
373
|
-
assert.equal(result, '')
|
|
374
|
-
})
|
|
375
|
-
|
|
376
|
-
it('returns the empty string when no token', () => {
|
|
377
|
-
// @ts-expect-error for testing
|
|
378
|
-
const result = element.readTokenValue(undefined)
|
|
379
|
-
assert.equal(result, '')
|
|
380
|
-
})
|
|
381
|
-
})
|
|
382
|
-
|
|
383
|
-
describe('readTokenLabel()', () => {
|
|
384
|
-
let element: OidcAuthorization
|
|
385
|
-
|
|
386
|
-
beforeEach(async () => {
|
|
387
|
-
element = await basicFixture({
|
|
388
|
-
...baseConfig,
|
|
389
|
-
issuerUri: env.oauth2.issuer,
|
|
390
|
-
})
|
|
391
|
-
})
|
|
392
|
-
|
|
393
|
-
it('returns the label for token response type', () => {
|
|
394
|
-
const result = element.readTokenLabel({
|
|
395
|
-
responseType: 'token',
|
|
396
|
-
state: '',
|
|
397
|
-
time: 1,
|
|
398
|
-
accessToken: 'test-token',
|
|
399
|
-
})
|
|
400
|
-
assert.equal(result, 'Access token')
|
|
401
|
-
})
|
|
402
|
-
|
|
403
|
-
it('returns the label for code response type', () => {
|
|
404
|
-
const result = element.readTokenLabel({
|
|
405
|
-
responseType: 'code',
|
|
406
|
-
state: '',
|
|
407
|
-
time: 1,
|
|
408
|
-
accessToken: 'test-token',
|
|
409
|
-
})
|
|
410
|
-
assert.equal(result, 'Access token from code exchange')
|
|
411
|
-
})
|
|
412
|
-
|
|
413
|
-
it('returns the label for id_token response type', () => {
|
|
414
|
-
const result = element.readTokenLabel({
|
|
415
|
-
responseType: 'id_token',
|
|
416
|
-
state: '',
|
|
417
|
-
time: 1,
|
|
418
|
-
idToken: 'test-token',
|
|
419
|
-
})
|
|
420
|
-
assert.equal(result, 'ID token')
|
|
421
|
-
})
|
|
422
|
-
|
|
423
|
-
it('returns the label for id response type', () => {
|
|
424
|
-
const result = element.readTokenLabel({
|
|
425
|
-
responseType: 'id',
|
|
426
|
-
state: '',
|
|
427
|
-
time: 1,
|
|
428
|
-
idToken: 'test-token',
|
|
429
|
-
})
|
|
430
|
-
assert.equal(result, 'ID token')
|
|
431
|
-
})
|
|
432
|
-
|
|
433
|
-
it('returns the label from default', () => {
|
|
434
|
-
const result = element.readTokenLabel({
|
|
435
|
-
responseType: 'other',
|
|
436
|
-
state: '',
|
|
437
|
-
time: 1,
|
|
438
|
-
accessToken: 'test-token',
|
|
439
|
-
})
|
|
440
|
-
assert.equal(result, 'Unknown token')
|
|
441
|
-
})
|
|
442
|
-
})
|
|
443
|
-
|
|
444
|
-
describe('serialize()', () => {
|
|
445
|
-
let element: OidcAuthorization
|
|
446
|
-
|
|
447
|
-
beforeEach(async () => {
|
|
448
|
-
element = await basicFixture({
|
|
449
|
-
issuerUri: env.oauth2.issuer,
|
|
450
|
-
clientId: 'test-cid',
|
|
451
|
-
clientSecret: 'test-secret',
|
|
452
|
-
grantType: 'authorization_code',
|
|
453
|
-
})
|
|
454
|
-
await element.discover()
|
|
455
|
-
})
|
|
456
|
-
|
|
457
|
-
it('sets the responseType', () => {
|
|
458
|
-
const result = element.serialize()
|
|
459
|
-
assert.equal(result.responseType, 'code')
|
|
460
|
-
})
|
|
461
|
-
|
|
462
|
-
it('sets the accessToken when has tokens', () => {
|
|
463
|
-
element.config.tokens = [
|
|
464
|
-
{
|
|
465
|
-
responseType: 'code',
|
|
466
|
-
state: 'abc',
|
|
467
|
-
time: 1,
|
|
468
|
-
accessToken: 'test-token',
|
|
469
|
-
},
|
|
470
|
-
]
|
|
471
|
-
const result = element.serialize()
|
|
472
|
-
assert.equal(result.accessToken, 'test-token')
|
|
473
|
-
})
|
|
474
|
-
|
|
475
|
-
it('has no accessToken when no tokens', () => {
|
|
476
|
-
element.config.tokens = undefined
|
|
477
|
-
const result = element.serialize()
|
|
478
|
-
assert.isUndefined(result.accessToken)
|
|
479
|
-
})
|
|
480
|
-
|
|
481
|
-
it('adds the issuerUri property', () => {
|
|
482
|
-
const result = element.serialize()
|
|
483
|
-
assert.equal(result.issuerUri, env.oauth2.issuer)
|
|
484
|
-
})
|
|
485
|
-
|
|
486
|
-
it('adds the tokens property', () => {
|
|
487
|
-
const tokens = [
|
|
488
|
-
{
|
|
489
|
-
responseType: 'code',
|
|
490
|
-
state: 'abc',
|
|
491
|
-
time: 1,
|
|
492
|
-
accessToken: 'test-token',
|
|
493
|
-
},
|
|
494
|
-
]
|
|
495
|
-
element.config.tokens = tokens
|
|
496
|
-
const result = element.serialize()
|
|
497
|
-
assert.deepEqual(result.tokens, tokens)
|
|
498
|
-
})
|
|
499
|
-
|
|
500
|
-
it('adds the tokenInUse property', () => {
|
|
501
|
-
const tokens = [
|
|
502
|
-
{
|
|
503
|
-
responseType: 'code',
|
|
504
|
-
state: 'abc',
|
|
505
|
-
time: 1,
|
|
506
|
-
accessToken: 'test-token',
|
|
507
|
-
},
|
|
508
|
-
]
|
|
509
|
-
element.config.tokens = tokens
|
|
510
|
-
element.config.tokenInUse = 1
|
|
511
|
-
const result = element.serialize()
|
|
512
|
-
assert.equal(result.tokenInUse, 1)
|
|
513
|
-
})
|
|
514
|
-
|
|
515
|
-
it('adds the supportedResponses property', () => {
|
|
516
|
-
const responses = [[{ label: 'a', type: 'b' }]]
|
|
517
|
-
element.config.supportedResponses = responses
|
|
518
|
-
const result = element.serialize()
|
|
519
|
-
assert.deepEqual(result.supportedResponses, responses)
|
|
520
|
-
})
|
|
521
|
-
|
|
522
|
-
it('adds the grantTypes property', () => {
|
|
523
|
-
const grantTypes = [{ label: 'a', type: 'b' }]
|
|
524
|
-
element.config.grantTypes = grantTypes
|
|
525
|
-
const result = element.serialize()
|
|
526
|
-
assert.deepEqual(result.grantTypes, grantTypes)
|
|
527
|
-
})
|
|
528
|
-
|
|
529
|
-
it('adds the serverScopes property', () => {
|
|
530
|
-
const serverScopes = ['a']
|
|
531
|
-
element.config.serverScopes = serverScopes
|
|
532
|
-
const result = element.serialize()
|
|
533
|
-
assert.deepEqual(result.serverScopes, serverScopes)
|
|
534
|
-
})
|
|
535
|
-
})
|
|
536
|
-
|
|
537
|
-
describe('authorize()', () => {
|
|
538
|
-
let element: OidcAuthorization
|
|
539
|
-
|
|
540
|
-
beforeEach(async () => {
|
|
541
|
-
element = await basicFixture({
|
|
542
|
-
...baseConfig,
|
|
543
|
-
issuerUri: env.oauth2.issuer,
|
|
544
|
-
clientId: 'test-cid',
|
|
545
|
-
clientSecret: 'test-secret',
|
|
546
|
-
grantType: 'authorization_code',
|
|
547
|
-
})
|
|
548
|
-
await element.discover()
|
|
549
|
-
})
|
|
550
|
-
|
|
551
|
-
function handler(e: Event): void {
|
|
552
|
-
const typed = e as ContextEvent<IOidcAuthorization, (IOidcTokenInfo | IOidcTokenError)[]>
|
|
553
|
-
const config = { ...typed.detail }
|
|
554
|
-
const auth = new OidcAuthorizationFactory(config)
|
|
555
|
-
typed.detail.result = auth.authorize()
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
before(() => {
|
|
559
|
-
document.body.addEventListener(EventTypes.Authorization.Oidc.authorize, handler)
|
|
560
|
-
})
|
|
561
|
-
|
|
562
|
-
after(() => {
|
|
563
|
-
document.body.removeEventListener(EventTypes.Authorization.Oidc.authorize, handler)
|
|
564
|
-
})
|
|
565
|
-
|
|
566
|
-
it('sets the state before authorization', async () => {
|
|
567
|
-
element.lastErrorMessage = 'test'
|
|
568
|
-
element.authorizing = false
|
|
569
|
-
const promise = element.authorize()
|
|
570
|
-
assert.isUndefined(element.lastErrorMessage, 'clears the lastErrorMessage')
|
|
571
|
-
assert.isTrue(element.authorizing, 'sets the authorizing')
|
|
572
|
-
await promise
|
|
573
|
-
})
|
|
574
|
-
|
|
575
|
-
it('sets the state after authorization', async () => {
|
|
576
|
-
element.config.accessToken = 'test'
|
|
577
|
-
element.requestUpdate()
|
|
578
|
-
await element.updateComplete
|
|
579
|
-
await element.authorize()
|
|
580
|
-
assert.typeOf(element.config.tokens, 'array', 'has the tokens set')
|
|
581
|
-
const token = element.config.tokens![0] as IOidcTokenInfo
|
|
582
|
-
assert.equal(token.responseType, 'code', 'has the responseType')
|
|
583
|
-
assert.typeOf(token.accessToken, 'string', 'has the accessToken')
|
|
584
|
-
assert.typeOf(token.idToken, 'string', 'has the idToken')
|
|
585
|
-
assert.isFalse(element.authorizing, 're-sets authorizing flag')
|
|
586
|
-
assert.isUndefined(element.config.accessToken, 'accessToken is removed')
|
|
587
|
-
assert.equal(element.config.tokenInUse, 0, 'tokenInUse is set')
|
|
588
|
-
})
|
|
589
|
-
})
|
|
590
|
-
})
|
|
591
|
-
})
|