-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(admin-ui): need api test cases for auth-server module #1251
- Loading branch information
1 parent
0a1590a
commit 5973619
Showing
26 changed files
with
749 additions
and
14 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
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
71 changes: 71 additions & 0 deletions
71
admin-ui/plugins/auth-server/_tests_/clients/api/Agama.test.js
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,71 @@ | ||
import { authReducerInit, beforeAllAsync } from './setup.test' | ||
import { expectSaga } from 'redux-saga-test-plan' | ||
import authReducer from 'Redux/features/authSlice' | ||
import { | ||
getAgamas, | ||
addAgama, | ||
deleteAgamas, | ||
} from 'Plugins/auth-server/redux/sagas/AgamaSaga' | ||
import { | ||
initialState as agamaInitState, | ||
reducer as agamaReducer, | ||
} from 'Plugins/auth-server/redux/features/agamaSlice' | ||
import { log } from 'console' | ||
import { combineReducers } from '@reduxjs/toolkit' | ||
|
||
let initialState | ||
|
||
const formInitState = (token, issuer) => { | ||
initialState = { | ||
authReducer: authReducerInit(token, issuer), | ||
agamaReducer: agamaInitState, | ||
} | ||
} | ||
|
||
beforeAll(async () => { | ||
try { | ||
await beforeAllAsync(formInitState) | ||
} catch (error) { | ||
log(error.message) | ||
} | ||
}) | ||
|
||
const rootReducer = combineReducers({ | ||
authReducer, | ||
agamaReducer, | ||
}) | ||
|
||
describe('api CRUD actions perform for agama', () => { | ||
it('GET Agama projects', async () => { | ||
const result = await expectSaga(getAgamas) | ||
.withReducer(rootReducer, initialState) | ||
.run(false) | ||
|
||
expect(result.returnValue instanceof Error).toBe(false) | ||
}) | ||
|
||
it('create new Agama project', async () => { | ||
const result = await expectSaga(addAgama, { | ||
payload: { | ||
name: 'test', | ||
file: 'test', | ||
}, | ||
}) | ||
.withReducer(rootReducer, initialState) | ||
.run(false) | ||
|
||
expect(result.returnValue instanceof Error).toBe(false) | ||
}) | ||
|
||
it('should delete newly created agama project', async () => { | ||
const result = await expectSaga(deleteAgamas, { | ||
payload: { | ||
name: 'test', | ||
}, | ||
}) | ||
.withReducer(rootReducer, initialState) | ||
.run(false) | ||
|
||
expect(result.returnValue instanceof Error).toBe(false) | ||
}) | ||
}) |
65 changes: 65 additions & 0 deletions
65
admin-ui/plugins/auth-server/_tests_/clients/api/AuthN.test.js
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,65 @@ | ||
import { expectSaga } from 'redux-saga-test-plan' | ||
import { authReducerInit, beforeAllAsync } from './setup.test' | ||
import { getScriptsByType } from 'Plugins/admin/redux/sagas/CustomScriptSaga' | ||
import { editSimpleAuthAcr } from 'Plugins/auth-server/redux/sagas/AuthnSaga' | ||
import { | ||
reducer as customScriptReducer, | ||
initialState as customScriptInitState, | ||
} from 'Plugins/admin/redux/features/customScriptSlice' | ||
import { combineReducers } from '@reduxjs/toolkit' | ||
import authReducer from 'Redux/features/authSlice' | ||
import { log } from 'console' | ||
|
||
let initialState | ||
|
||
const formInitState = (token, issuer) => { | ||
initialState = { | ||
authReducer: authReducerInit(token, issuer), | ||
customScriptReducer: customScriptInitState, | ||
} | ||
} | ||
|
||
beforeAll(async () => { | ||
try { | ||
await beforeAllAsync(formInitState) | ||
} catch (error) { | ||
log(error.message) | ||
} | ||
}) | ||
|
||
const rootReducer = combineReducers({ | ||
customScriptReducer, | ||
authReducer, | ||
}) | ||
|
||
describe('api tests for authn module', () => { | ||
let defaultAuthNMethod | ||
it('should get custom script by type person_authentication', async () => { | ||
const result = await expectSaga(getScriptsByType, { | ||
payload: { action: { type: 'person_authentication' } }, | ||
}) | ||
.withReducer(rootReducer, initialState) | ||
.silentRun(false) | ||
|
||
defaultAuthNMethod = result.returnValue?.entries?.find( | ||
(item) => item.name === 'simple_password_auth' | ||
) | ||
expect(result.returnValue instanceof Error).toBe(false) | ||
if (result.returnValue.entries) { | ||
expect(result.storeState.customScriptReducer.items).toBe( | ||
result.returnValue.entries | ||
) | ||
} | ||
}) | ||
|
||
it('should save the default authn method to simple_password_auth', async () => { | ||
const result = await expectSaga(editSimpleAuthAcr, { | ||
payload: { data: { authenticationMethod: { defaultAcr: "simple_password_auth" } } }, | ||
}) | ||
.withReducer(rootReducer, initialState) | ||
.silentRun(false) | ||
|
||
log(`result.returnValue`, result.returnValue) | ||
expect(result.returnValue instanceof Error).toBe(false) | ||
}) | ||
}) |
41 changes: 41 additions & 0 deletions
41
admin-ui/plugins/auth-server/_tests_/clients/api/Jwks.test.js
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,41 @@ | ||
import { log } from 'console' | ||
import { authReducerInit, beforeAllAsync } from './setup.test' | ||
import authReducer from 'Redux/features/authSlice' | ||
import { getJwksConfig } from 'Plugins/auth-server/redux/sagas/JwksSaga' | ||
import { combineReducers } from '@reduxjs/toolkit' | ||
import { expectSaga } from 'redux-saga-test-plan' | ||
import { reducer as jwksReducer } from 'Plugins/auth-server/redux/features/jwksSlice' | ||
|
||
let initialState | ||
|
||
const formInitState = (token, issuer) => { | ||
initialState = { | ||
authReducer: authReducerInit(token, issuer), | ||
jwksReducer: { | ||
jwks: {}, | ||
}, | ||
} | ||
} | ||
|
||
beforeAll(async () => { | ||
try { | ||
await beforeAllAsync(formInitState) | ||
} catch (error) { | ||
log(error.message) | ||
} | ||
}) | ||
|
||
const rootReducer = combineReducers({ | ||
authReducer, | ||
jwksReducer, | ||
}) | ||
|
||
describe('fetch & update json configuration', () => { | ||
it('should GET current JSON configs', async () => { | ||
const result = await expectSaga(getJwksConfig) | ||
.withReducer(rootReducer, initialState) | ||
.run(false) | ||
|
||
expect(result.returnValue instanceof Error).toBe(false) | ||
}) | ||
}) |
90 changes: 90 additions & 0 deletions
90
admin-ui/plugins/auth-server/_tests_/clients/api/Logging.test.js
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,90 @@ | ||
import { | ||
getLogging, | ||
editLogging, | ||
} from 'Plugins/auth-server/redux/sagas/LoggingSaga' | ||
import { authReducerInit, beforeAllAsync } from './setup.test' | ||
import { combineReducers } from '@reduxjs/toolkit' | ||
import authReducer from 'Redux/features/authSlice' | ||
import { reducer as loggingReducer } from 'Plugins/auth-server/redux/features/loggingSlice' | ||
import { expectSaga } from 'redux-saga-test-plan' | ||
import { log } from 'console' | ||
|
||
let initialState | ||
|
||
const formInitState = (token, issuer) => { | ||
initialState = { | ||
authReducer: authReducerInit(token, issuer), | ||
loggingReducer: { | ||
logging: {}, | ||
}, | ||
} | ||
} | ||
|
||
beforeAll(async () => { | ||
try { | ||
await beforeAllAsync(formInitState) | ||
} catch (error) { | ||
log(error.message) | ||
} | ||
}) | ||
|
||
const rootReducer = combineReducers({ | ||
authReducer, | ||
loggingReducer, | ||
}) | ||
|
||
describe('test GET & update action for logging page', () => { | ||
let configs | ||
|
||
it('GET current logging config', async () => { | ||
const result = await expectSaga(getLogging) | ||
.withReducer(rootReducer, initialState) | ||
.silentRun(false) | ||
|
||
configs = result.returnValue | ||
expect(result.returnValue instanceof Error).toBe(false) | ||
expect(result.returnValue).toEqual(result.storeState.loggingReducer.logging) | ||
}) | ||
|
||
it('update httpLoggingEnabled from current logging config', async () => { | ||
if (!(configs instanceof Error)) { | ||
const result = await expectSaga(editLogging, { | ||
payload: { | ||
data: { | ||
logging: { | ||
...configs, | ||
httpLoggingEnabled: !configs.httpLoggingEnabled, | ||
}, | ||
}, | ||
}, | ||
}) | ||
.withReducer(rootReducer, initialState) | ||
.silentRun(false) | ||
|
||
expect(result.returnValue instanceof Error).toBe(false) | ||
} else { | ||
log('Error occured while fetching') | ||
} | ||
}) | ||
|
||
it('should toggle back value of httpLoggingEnabled', async () => { | ||
if (!(configs instanceof Error)) { | ||
const result = await expectSaga(editLogging, { | ||
payload: { | ||
data: { | ||
logging: { | ||
...configs, | ||
httpLoggingEnabled: configs.httpLoggingEnabled, | ||
}, | ||
}, | ||
}, | ||
}) | ||
.withReducer(rootReducer, initialState) | ||
.silentRun(false) | ||
|
||
expect(result.returnValue instanceof Error).toBe(false) | ||
} else { | ||
log('Error occured while fetching') | ||
} | ||
}) | ||
}) |
Oops, something went wrong.