Skip to content

Commit 237a3a5

Browse files
committed
fix(admin-ui): write test for Openid connect client pages #295
1 parent b008af6 commit 237a3a5

File tree

2 files changed

+291
-0
lines changed

2 files changed

+291
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import React from 'react'
2+
import { render, screen } from '@testing-library/react'
3+
import ClientAddPage from './ClientAddPage'
4+
import { combineReducers } from 'redux'
5+
import { BrowserRouter as Router } from 'react-router-dom'
6+
import { createStore } from 'redux'
7+
import { Provider } from 'react-redux'
8+
import i18n from '../../../../app/i18n'
9+
import { I18nextProvider } from 'react-i18next'
10+
import authReducer from '../../../../app/redux/reducers/AuthReducer'
11+
import initReducer from '../../../../app/redux/reducers/InitReducer'
12+
import oidcDiscoveryReducer from '../../../../app/redux/reducers/OidcDiscoveryReducer'
13+
import oidcReducer from '../../redux/reducers/OIDCReducer'
14+
import scopeReducer from '../../redux/reducers/ScopeReducer'
15+
const scopes = []
16+
const permissions = [
17+
'https://jans.io/oauth/config/openid/clients.readonly',
18+
'https://jans.io/oauth/config/openid/clients.write',
19+
'https://jans.io/oauth/config/openid/clients.delete',
20+
]
21+
const INIT_STATE = {
22+
isAuthenticated: false,
23+
userinfo: null,
24+
userinfo_jwt: null,
25+
token: null,
26+
issuer: null,
27+
permissions: permissions,
28+
location: {},
29+
config: {},
30+
backendIsUp: true,
31+
}
32+
33+
const INIT_CLIENTS_STATE = {
34+
items: [],
35+
item: {},
36+
view: false,
37+
loading: false,
38+
}
39+
40+
const INIT_SCPOPES_STATE = {
41+
items: [
42+
{
43+
id: 'https://jans.io/oauth/config/smtp.delete',
44+
scopeType: 'oauth',
45+
dn: 'inum=1800.85A227,ou=scopes,o=jans',
46+
inum: '1800.85A227',
47+
displayName: 'Config API scope https://jans.io/oauth/config/smtp.delete',
48+
description: 'Delete SMTP related information',
49+
defaultScope: false,
50+
attributes: { showInConfigurationEndpoint: false },
51+
umaType: false,
52+
tableData: { id: 0 },
53+
},
54+
],
55+
item: {},
56+
loading: false,
57+
}
58+
const store = createStore(
59+
combineReducers({
60+
authReducer: (state = INIT_STATE) => state,
61+
oidcReducer: (state = INIT_SCPOPES_STATE) => state,
62+
scopeReducer,
63+
initReducer,
64+
oidcDiscoveryReducer,
65+
noReducer: (state = {}) => state,
66+
}),
67+
)
68+
69+
const Wrapper = ({ children }) => (
70+
<I18nextProvider i18n={i18n}>
71+
<Provider store={store}>
72+
<Router basename="/admin">{children}</Router>
73+
</Provider>
74+
</I18nextProvider>
75+
)
76+
const emptyArray = []
77+
78+
it('Should show the sidebar properly', () => {
79+
render(
80+
<ClientAddPage
81+
scopes={scopes}
82+
permissions={permissions}
83+
scopes={emptyArray}
84+
/>,
85+
{ wrapper: Wrapper },
86+
)
87+
screen.getByText(/Basic/)
88+
screen.getByText(/Advanced/)
89+
screen.getByText('Encryption/Signing')
90+
screen.getByText(/Client Attributes/)
91+
screen.getByText(/Client Scripts/)
92+
screen.getByText(/Client Name/)
93+
screen.getByText(/The openid connect client name/)
94+
screen.getByText(/description/)
95+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
import React from 'react'
2+
import { render, screen } from '@testing-library/react'
3+
import ClientEditPage from './ClientEditPage'
4+
import { combineReducers } from 'redux'
5+
import { BrowserRouter as Router } from 'react-router-dom'
6+
import { createStore } from 'redux'
7+
import { Provider } from 'react-redux'
8+
import i18n from '../../../../app/i18n'
9+
import { I18nextProvider } from 'react-i18next'
10+
import authReducer from '../../../../app/redux/reducers/AuthReducer'
11+
import initReducer from '../../../../app/redux/reducers/InitReducer'
12+
import oidcDiscoveryReducer from '../../../../app/redux/reducers/OidcDiscoveryReducer'
13+
import oidcReducer from '../../redux/reducers/OIDCReducer'
14+
import scopeReducer from '../../redux/reducers/ScopeReducer'
15+
const scopes = []
16+
const permissions = [
17+
'https://jans.io/oauth/config/openid/clients.readonly',
18+
'https://jans.io/oauth/config/openid/clients.write',
19+
'https://jans.io/oauth/config/openid/clients.delete',
20+
]
21+
const INIT_STATE = {
22+
isAuthenticated: false,
23+
userinfo: null,
24+
userinfo_jwt: null,
25+
token: null,
26+
issuer: null,
27+
permissions: permissions,
28+
location: {},
29+
config: {},
30+
backendIsUp: true,
31+
}
32+
33+
const INIT_CLIENTS_STATE = {
34+
items: [
35+
{
36+
applicationType: 'web',
37+
includeClaimsInIdToken: false,
38+
dn: 'inum=2073c8e7-1060-4c09-b0f6-7d46fb6ff8f5,ou=clients,o=jans',
39+
inum: '2073c8e7-1060-4c09-b0f6-7d46fb6ff8f5',
40+
clientSecret: '92bc4d8e-2f4c-4a4d-80ae-1e4eb1f5f463',
41+
frontChannelLogoutUri: 'http://localhost:4100/logout',
42+
frontChannelLogoutSessionRequired: false,
43+
registrationAccessToken: 'de5aaa9c-d6b4-44a1-912f-40c97063544a',
44+
clientIdIssuedAt: '2021-07-28T06:35:09.000Z',
45+
redirectUris: [
46+
'http://localhost:4100',
47+
'https://admin-ui-test.gluu.org/admin',
48+
],
49+
responseTypes: ['code'],
50+
grantTypes: ['authorization_code', 'refresh_token', 'client_credentials'],
51+
clientName: 'admin-ui',
52+
subjectType: 'pairwise',
53+
idTokenSignedResponseAlg: 'RS256',
54+
userInfoSignedResponseAlg: 'RS256',
55+
tokenEndpointAuthMethod: 'client_secret_basic',
56+
requireAuthTime: false,
57+
defaultAcrValues: ['simple_password_auth'],
58+
postLogoutRedirectUris: [
59+
'http://localhost:4100',
60+
'https://admin-ui-test.gluu.org/admin',
61+
],
62+
scopes: [
63+
'inum=F0C4,ou=scopes,o=jans',
64+
'inum=6D90,ou=scopes,o=jans',
65+
'inum=43F1,ou=scopes,o=jans',
66+
],
67+
trustedClient: false,
68+
lastAccessTime: '2021-07-28T06:35:09.000Z',
69+
lastLogonTime: '2021-07-28T06:35:09.000Z',
70+
persistClientAuthorizations: true,
71+
customAttributes: [],
72+
customObjectClasses: ['top'],
73+
rptAsJwt: false,
74+
accessTokenAsJwt: true,
75+
accessTokenSigningAlg: 'RS256',
76+
disabled: false,
77+
attributes: {
78+
runIntrospectionScriptBeforeAccessTokenAsJwtCreationAndIncludeClaims: false,
79+
keepClientAuthorizationAfterExpiration: false,
80+
allowSpontaneousScopes: false,
81+
backchannelLogoutSessionRequired: false,
82+
},
83+
deletable: false,
84+
},
85+
],
86+
item: {
87+
applicationType: 'web',
88+
includeClaimsInIdToken: false,
89+
dn: 'inum=2073c8e7-1060-4c09-b0f6-7d46fb6ff8f5,ou=clients,o=jans',
90+
inum: '2073c8e7-1060-4c09-b0f6-7d46fb6ff8f5',
91+
clientSecret: '92bc4d8e-2f4c-4a4d-80ae-1e4eb1f5f463',
92+
frontChannelLogoutUri: 'http://localhost:4100/logout',
93+
frontChannelLogoutSessionRequired: false,
94+
registrationAccessToken: 'de5aaa9c-d6b4-44a1-912f-40c97063544a',
95+
clientIdIssuedAt: '2021-07-28T06:35:09.000Z',
96+
redirectUris: [
97+
'http://localhost:4100',
98+
'https://admin-ui-test.gluu.org/admin',
99+
],
100+
responseTypes: ['code'],
101+
grantTypes: ['authorization_code', 'refresh_token', 'client_credentials'],
102+
clientName: 'admin-ui',
103+
subjectType: 'pairwise',
104+
idTokenSignedResponseAlg: 'RS256',
105+
userInfoSignedResponseAlg: 'RS256',
106+
tokenEndpointAuthMethod: 'client_secret_basic',
107+
requireAuthTime: false,
108+
defaultAcrValues: ['simple_password_auth'],
109+
postLogoutRedirectUris: [
110+
'http://localhost:4100',
111+
'https://admin-ui-test.gluu.org/admin',
112+
],
113+
scopes: [
114+
'inum=F0C4,ou=scopes,o=jans',
115+
'inum=6D90,ou=scopes,o=jans',
116+
'inum=43F1,ou=scopes,o=jans',
117+
],
118+
trustedClient: false,
119+
lastAccessTime: '2021-07-28T06:35:09.000Z',
120+
lastLogonTime: '2021-07-28T06:35:09.000Z',
121+
persistClientAuthorizations: true,
122+
customAttributes: [],
123+
customObjectClasses: ['top'],
124+
rptAsJwt: false,
125+
accessTokenAsJwt: true,
126+
accessTokenSigningAlg: 'RS256',
127+
disabled: false,
128+
attributes: {
129+
runIntrospectionScriptBeforeAccessTokenAsJwtCreationAndIncludeClaims: false,
130+
keepClientAuthorizationAfterExpiration: false,
131+
allowSpontaneousScopes: false,
132+
backchannelLogoutSessionRequired: false,
133+
},
134+
deletable: false,
135+
},
136+
view: false,
137+
loading: false,
138+
}
139+
140+
const INIT_SCPOPES_STATE = {
141+
items: [
142+
{
143+
id: 'https://jans.io/oauth/config/smtp.delete',
144+
scopeType: 'oauth',
145+
dn: 'inum=1800.85A227,ou=scopes,o=jans',
146+
inum: '1800.85A227',
147+
displayName: 'Config API scope https://jans.io/oauth/config/smtp.delete',
148+
description: 'Delete SMTP related information',
149+
defaultScope: false,
150+
attributes: { showInConfigurationEndpoint: false },
151+
umaType: false,
152+
tableData: { id: 0 },
153+
},
154+
],
155+
item: {},
156+
loading: false,
157+
}
158+
const store = createStore(
159+
combineReducers({
160+
authReducer: (state = INIT_STATE) => state,
161+
oidcReducer: (state = INIT_CLIENTS_STATE) => state,
162+
scopeReducer,
163+
initReducer,
164+
oidcDiscoveryReducer,
165+
noReducer: (state = {}) => state,
166+
}),
167+
)
168+
169+
const Wrapper = ({ children }) => (
170+
<I18nextProvider i18n={i18n}>
171+
<Provider store={store}>
172+
<Router basename="/admin">{children}</Router>
173+
</Provider>
174+
</I18nextProvider>
175+
)
176+
const emptyArray = []
177+
178+
it('Should the client edit page properly properly', () => {
179+
render(
180+
<ClientEditPage
181+
scopes={scopes}
182+
permissions={permissions}
183+
scopes={emptyArray}
184+
/>,
185+
{ wrapper: Wrapper },
186+
)
187+
screen.getByText(/Basic/)
188+
screen.getByText(/Advanced/)
189+
screen.getByText('Encryption/Signing')
190+
screen.getByText(/Client Attributes/)
191+
screen.getByText(/Client Scripts/)
192+
screen.getByText(/Client Name/)
193+
screen.getByText(/The openid connect client name/)
194+
screen.getByText(/The openid connect client id/)
195+
screen.getByText(/Inum/)
196+
})

0 commit comments

Comments
 (0)