Skip to content

Commit 29cf468

Browse files
committed
fix(admin-ui): not able to add source backend ldap server in jans-link #1252
1 parent 0a1590a commit 29cf468

32 files changed

+765
-64
lines changed

admin-ui/__tests__/setup.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
jest.spyOn(global.console, 'log').mockImplementation(jest.fn())
22
jest.spyOn(global.console, 'warn').mockImplementation(jest.fn())
33
jest.setTimeout(30000);
4+
// Polyfill "window.fetch" used in the React component.
5+
import 'whatwg-fetch'
46
import '@testing-library/jest-dom'
57

68
it('Jans-admin UI test setup', () => {

admin-ui/app/redux/sagas/LicenseSaga.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function* checkLicensePresentWorker() {
4343
const licenseApi = yield* getApiTokenWithDefaultScopes()
4444
const response = yield call(licenseApi.getIsActive)
4545
if (response) {
46-
yield put(checkLicensePresentResponse({ isLicenseValid: response.apiResult }))
46+
yield put(checkLicensePresentResponse({ isLicenseValid: true }))
4747
return
4848
}
4949
yield put(checkLicensePresentResponse({ isLicenseValid: false }))
@@ -66,7 +66,7 @@ function* generateTrailLicenseKey() {
6666
}
6767
})
6868
yield put(generateTrialLicenseResponse(activateLicense))
69-
yield put(checkLicensePresentResponse({ isLicenseValid: activateLicense?.apiResult }))
69+
yield put(checkLicensePresentResponse({ isLicenseValid: true }))
7070
yield put(checkUserLicenseKeyResponse(activateLicense))
7171
} catch (error) {
7272
yield put(checkLicensePresentResponse({ isLicenseValid: false }))
@@ -98,7 +98,7 @@ function* uploadNewSsaToken({ payload }) {
9898
)
9999
)
100100
}
101-
yield put(checkLicenseConfigValidResponse(response?.apiResult))
101+
yield put(checkLicenseConfigValidResponse(true))
102102
yield put(getOAuth2Config(defaultToken))
103103
yield put(checkLicensePresent())
104104
// window.location.reload()
@@ -112,7 +112,7 @@ function* checkAdminuiLicenseConfig() {
112112
const licenseApi = yield* getApiTokenWithDefaultScopes()
113113
yield put(getOAuth2Config(defaultToken))
114114
const response = yield call(licenseApi.checkAdminuiLicenseConfig)
115-
yield put(checkLicenseConfigValidResponse(response?.apiResult))
115+
yield put(checkLicenseConfigValidResponse(true))
116116
} catch (error) {
117117
console.log(error)
118118
}

admin-ui/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
"webpack-bundle-analyzer": "^4.8.0",
9696
"webpack-cli": "^5.0.1",
9797
"webpack-dev-server": "^4.13.2",
98+
"whatwg-fetch": "^3.6.17",
9899
"xhr2": "^0.2.1"
99100
},
100101
"dependencies": {

admin-ui/plugins/admin/redux/features/customScriptSlice.js

+1
Original file line numberDiff line numberDiff line change
@@ -116,5 +116,6 @@ export const {
116116
viewOnly,
117117
setCurrentItem
118118
} = customScriptSlice.actions
119+
export { initialState }
119120
export const { actions, reducer, state } = customScriptSlice
120121
reducerRegistry.register('customScriptReducer', reducer)

admin-ui/plugins/admin/redux/sagas/CustomScriptSaga.js

+2
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,14 @@ export function* getScriptsByType({ payload }) {
5555
const data = yield call(scriptApi.getScriptsByType, payload.action)
5656
yield put(getCustomScriptsResponse({ data }))
5757
yield call(postUserAction, audit)
58+
return data
5859
} catch (e) {
5960
yield put(getCustomScriptsResponse(null))
6061
if (isFourZeroOneError(e)) {
6162
const jwt = yield select((state) => state.authReducer.userinfo_jwt)
6263
yield put(getAPIAccessToken(jwt))
6364
}
65+
return e
6466
}
6567
}
6668
export function* addScript({ payload }) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { authReducerInit, beforeAllAsync } from './setup.test'
2+
import { expectSaga } from 'redux-saga-test-plan'
3+
import authReducer from 'Redux/features/authSlice'
4+
import {
5+
getAgamas,
6+
addAgama,
7+
deleteAgamas,
8+
} from 'Plugins/auth-server/redux/sagas/AgamaSaga'
9+
import {
10+
initialState as agamaInitState,
11+
reducer as agamaReducer,
12+
} from 'Plugins/auth-server/redux/features/agamaSlice'
13+
import { log } from 'console'
14+
import { combineReducers } from '@reduxjs/toolkit'
15+
16+
let initialState
17+
18+
const formInitState = (token, issuer) => {
19+
initialState = {
20+
authReducer: authReducerInit(token, issuer),
21+
agamaReducer: agamaInitState,
22+
}
23+
}
24+
25+
beforeAll(async () => {
26+
try {
27+
await beforeAllAsync(formInitState)
28+
} catch (error) {
29+
log(error.message)
30+
}
31+
})
32+
33+
const rootReducer = combineReducers({
34+
authReducer,
35+
agamaReducer,
36+
})
37+
38+
describe('api CRUD actions perform for agama', () => {
39+
it('GET Agama projects', async () => {
40+
const result = await expectSaga(getAgamas)
41+
.withReducer(rootReducer, initialState)
42+
.run(false)
43+
44+
expect(result.returnValue instanceof Error).toBe(false)
45+
})
46+
47+
it('create new Agama project', async () => {
48+
const result = await expectSaga(addAgama, {
49+
payload: {
50+
name: 'test',
51+
file: 'test',
52+
},
53+
})
54+
.withReducer(rootReducer, initialState)
55+
.run(false)
56+
57+
expect(result.returnValue instanceof Error).toBe(false)
58+
})
59+
60+
it('should delete newly created agama project', async () => {
61+
const result = await expectSaga(deleteAgamas, {
62+
payload: {
63+
name: 'test',
64+
},
65+
})
66+
.withReducer(rootReducer, initialState)
67+
.run(false)
68+
69+
expect(result.returnValue instanceof Error).toBe(false)
70+
})
71+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { expectSaga } from 'redux-saga-test-plan'
2+
import { authReducerInit, beforeAllAsync } from './setup.test'
3+
import { getScriptsByType } from 'Plugins/admin/redux/sagas/CustomScriptSaga'
4+
import { editSimpleAuthAcr } from 'Plugins/auth-server/redux/sagas/AuthnSaga'
5+
import {
6+
reducer as customScriptReducer,
7+
initialState as customScriptInitState,
8+
} from 'Plugins/admin/redux/features/customScriptSlice'
9+
import { combineReducers } from '@reduxjs/toolkit'
10+
import authReducer from 'Redux/features/authSlice'
11+
import { log } from 'console'
12+
13+
let initialState
14+
15+
const formInitState = (token, issuer) => {
16+
initialState = {
17+
authReducer: authReducerInit(token, issuer),
18+
customScriptReducer: customScriptInitState,
19+
}
20+
}
21+
22+
beforeAll(async () => {
23+
try {
24+
await beforeAllAsync(formInitState)
25+
} catch (error) {
26+
log(error.message)
27+
}
28+
})
29+
30+
const rootReducer = combineReducers({
31+
customScriptReducer,
32+
authReducer,
33+
})
34+
35+
describe('api tests for authn module', () => {
36+
let defaultAuthNMethod
37+
it('should get custom script by type person_authentication', async () => {
38+
const result = await expectSaga(getScriptsByType, {
39+
payload: { action: { type: 'person_authentication' } },
40+
})
41+
.withReducer(rootReducer, initialState)
42+
.silentRun(false)
43+
44+
defaultAuthNMethod = result.returnValue?.entries?.find(
45+
(item) => item.name === 'simple_password_auth'
46+
)
47+
expect(result.returnValue instanceof Error).toBe(false)
48+
if (result.returnValue.entries) {
49+
expect(result.storeState.customScriptReducer.items).toBe(
50+
result.returnValue.entries
51+
)
52+
}
53+
})
54+
55+
it('should save the default authn method to simple_password_auth', async () => {
56+
const result = await expectSaga(getScriptsByType, {
57+
payload: { data: { authenticationMethod: 'simple_password_auth' } },
58+
})
59+
.withReducer(rootReducer, initialState)
60+
.silentRun(false)
61+
62+
expect(result.returnValue instanceof Error).toBe(false)
63+
})
64+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { log } from 'console'
2+
import { authReducerInit, beforeAllAsync } from './setup.test'
3+
import authReducer from 'Redux/features/authSlice'
4+
import getJwksConfig from 'Plugins/auth-server/redux/sagas/JwksSaga'
5+
import { combineReducers } from '@reduxjs/toolkit'
6+
import { expectSaga } from 'redux-saga-test-plan'
7+
import { reducer as jwksReducer } from 'Plugins/auth-server/redux/features/jwksSlice'
8+
9+
let initialState
10+
11+
const formInitState = (token, issuer) => {
12+
initialState = {
13+
authReducer: authReducerInit(token, issuer),
14+
jwksReducer: {
15+
jwks: {},
16+
},
17+
}
18+
}
19+
20+
beforeAll(async () => {
21+
try {
22+
await beforeAllAsync(formInitState)
23+
} catch (error) {
24+
log(error.message)
25+
}
26+
})
27+
28+
const rootReducer = combineReducers({
29+
authReducer,
30+
jwksReducer,
31+
})
32+
33+
describe('fetch & update json configuration', () => {
34+
it('should GET current JSON configs', async () => {
35+
const result = await expectSaga(getJwksConfig)
36+
.withReducer(rootReducer, initialState)
37+
.run(false)
38+
39+
expect(result.returnValue instanceof Error).toBe(false)
40+
})
41+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import {
2+
getLogging,
3+
editLogging,
4+
} from 'Plugins/auth-server/redux/sagas/LoggingSaga'
5+
import { authReducerInit, beforeAllAsync } from './setup.test'
6+
import { combineReducers } from '@reduxjs/toolkit'
7+
import authReducer from 'Redux/features/authSlice'
8+
import { reducer as loggingReducer } from 'Plugins/auth-server/redux/features/loggingSlice'
9+
import { expectSaga } from 'redux-saga-test-plan'
10+
import { log } from 'console'
11+
12+
let initialState
13+
14+
const formInitState = (token, issuer) => {
15+
initialState = {
16+
authReducer: authReducerInit(token, issuer),
17+
loggingReducer: {
18+
logging: {},
19+
},
20+
}
21+
}
22+
23+
beforeAll(async () => {
24+
try {
25+
await beforeAllAsync(formInitState)
26+
} catch (error) {
27+
log(error.message)
28+
}
29+
})
30+
31+
const rootReducer = combineReducers({
32+
authReducer,
33+
loggingReducer,
34+
})
35+
36+
describe('test GET & update action for logging page', () => {
37+
let configs
38+
39+
it('GET current logging config', async () => {
40+
const result = await expectSaga(getLogging)
41+
.withReducer(rootReducer, initialState)
42+
.silentRun(false)
43+
44+
configs = result.returnValue
45+
expect(result.returnValue instanceof Error).toBe(false)
46+
expect(result.returnValue).toEqual(result.storeState.loggingReducer.logging)
47+
})
48+
49+
it('update httpLoggingEnabled from current logging config', async () => {
50+
if (!(configs instanceof Error)) {
51+
const result = await expectSaga(editLogging, {
52+
payload: {
53+
data: {
54+
logging: {
55+
...configs,
56+
httpLoggingEnabled: !configs.httpLoggingEnabled,
57+
},
58+
},
59+
},
60+
})
61+
.withReducer(rootReducer, initialState)
62+
.silentRun(false)
63+
64+
expect(result.returnValue instanceof Error).toBe(false)
65+
} else {
66+
log('Error occured while fetching')
67+
}
68+
})
69+
70+
it('should toggle back value of httpLoggingEnabled', async () => {
71+
if (!(configs instanceof Error)) {
72+
const result = await expectSaga(editLogging, {
73+
payload: {
74+
data: {
75+
logging: {
76+
...configs,
77+
httpLoggingEnabled: configs.httpLoggingEnabled,
78+
},
79+
},
80+
},
81+
})
82+
.withReducer(rootReducer, initialState)
83+
.silentRun(false)
84+
85+
expect(result.returnValue instanceof Error).toBe(false)
86+
} else {
87+
log('Error occured while fetching')
88+
}
89+
})
90+
})

0 commit comments

Comments
 (0)