Skip to content

Commit

Permalink
fix(admin-ui): write test for all pages under auth-server plugin #301
Browse files Browse the repository at this point in the history
  • Loading branch information
syntrydy committed Nov 12, 2021
1 parent 7d31e72 commit ea4d016
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 13 deletions.
1 change: 0 additions & 1 deletion plugins/auth-server/components/Configuration/ConfigPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ function ConfigPage({ configuration, loading, dispatch }) {
const [modal, setModal] = useState(false)
const [patches, setPatches] = useState([])
const [showExitPrompt, setShowExitPrompt] = useExitPrompt(true)
console.log(JSON.stringify(configuration))
useEffect(() => {
buildPayload(userAction, FETCHING_JSON_PROPERTIES, {})
dispatch(getJsonConfig())
Expand Down
69 changes: 59 additions & 10 deletions plugins/auth-server/components/Configuration/Keys/Jwks/JwkItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,65 @@ function JwkItem({ item, index }) {
<FormGroup row>
<GluuLabel label="crv" size={1} />
<Col sm={2}>
<Input id="crv" name="crv" defaultValue={item.crv} />
<Input
id="crv"
data-testid="crv"
name="crv"
defaultValue={item.crv}
/>
</Col>
<GluuLabel label="exp" size={1} />
<Col sm={3}>
<Input id="exp" name="exp" defaultValue={item.exp} />
<Input
id="exp"
data-testid="exp"
name="exp"
defaultValue={item.exp}
/>
</Col>
<GluuLabel label="use" size={1} />
<Col sm={2}>
<Input id="use" name="use" defaultValue={item.use} />
<Input
id="use"
data-testid="use"
name="use"
defaultValue={item.use}
/>
</Col>
</FormGroup>
<FormGroup row>
<GluuLabel label="kty" size={1} />
<Col sm={2}>
<Input id="kty" name="kty" defaultValue={item.kty} />
<Input
id="kty"
data-testid="kty"
name="kty"
defaultValue={item.kty}
/>
</Col>
<GluuLabel label="alg" size={1} />
<Col sm={2}>
<Input id="alg" name="alg" defaultValue={item.alg} />
<Input
id="alg"
data-testid="alg"
name="alg"
defaultValue={item.alg}
/>
</Col>
<GluuLabel label="e" size={1} />
<Col sm={2}>
<Input id="e" name="e" defaultValue={item.e} />
<Input id="e" data-testid="e" name="e" defaultValue={item.e} />
</Col>
</FormGroup>
<FormGroup row>
<GluuLabel label="kid" size={1} />
<Col sm={6}>
<Input id="kid" name="kid" defaultValue={item.kid} />
<Input
id="kid"
data-testid="kid"
name="kid"
defaultValue={item.kid}
/>
</Col>
</FormGroup>
<FormGroup row>
Expand All @@ -56,6 +86,7 @@ function JwkItem({ item, index }) {
<Input
id="x5c"
type="textarea"
data-testid="x5c"
name="x5c"
defaultValue={item.x5c}
/>
Expand All @@ -65,19 +96,37 @@ function JwkItem({ item, index }) {
<FormGroup row>
<GluuLabel label="x" size={1} />
<Col sm={5}>
<Input id="x" type="textarea" name="x" defaultValue={item.x} />
<Input
id="x"
data-testid="x"
type="textarea"
name="x"
defaultValue={item.x}
/>
</Col>
<GluuLabel label="y" size={1} />
<Col sm={5}>
<Input id="y" type="textarea" name="y" defaultValue={item.y} />
<Input
id="y"
data-testid="y"
type="textarea"
name="y"
defaultValue={item.y}
/>
</Col>
</FormGroup>
)}
{item.n && (
<FormGroup row>
<GluuLabel label="n" size={1} />
<Col sm={11}>
<Input id="n" type="textarea" name="n" defaultValue={item.n} />
<Input
id="n"
data-testid="n"
type="textarea"
name="n"
defaultValue={item.n}
/>
</Col>
</FormGroup>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ import GluuLabel from '../../../../../../app/routes/Apps/Gluu/GluuLabel'
import GluuLoader from '../../../../../../app/routes/Apps/Gluu/GluuLoader'
import { connect } from 'react-redux'
import JwkItem from './JwkItem'
import { useTranslation } from 'react-i18next'

function JwksPage({ jwks, loading, dispatch }) {
const { t } = useTranslation()
useEffect(() => {
dispatch(getJwks())
}, [])
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import React from 'react'
import { render, screen } from '@testing-library/react'
import JwksPage from './JwksPage'
import { combineReducers, createStore } from 'redux'
import { Provider } from 'react-redux'
import i18n from '../../../../../../app/i18n'
import { I18nextProvider } from 'react-i18next'
const jwks_config = {
keys: [
{
kid: 'da42021d-a00d-4c39-a3e7-828f96045269_sig_rs256',
kty: 'RSA',
use: 'sig',
alg: 'RS256',
exp: 1636569490123,
x5c: [
'MIIDCTCCAfGgAwIBAgIgR4Vwlqjkzg6kyd6Hl4FzlLwfZgJJXcN7M7hX2DDOo20wDQYJKoZIhvcNAQELBQAwJDEiMCAGA1UEAwwZSmFucyBBdXRoIENBIENlcnRpZmljYXRlczAeFw0yMTExMDgxNzM4MDBaFw0yMTExMTAxODM4MTBaMCQxIjAgBgNVBAMMGUphbnMgQXV0aCBDQSBDZXJ0aWZpY2F0ZXMwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCZy3afNogPCRZ/I/aHhe2dsLO6qRU0/2vPvOy0y8A9gAzGKx9XMWaj8XJIsRY34QUmDiK7THhiOBKVNTb5hcSk95lsvoQ7EFaEg+JxmS8Wsvz2n/Smnob9Fc++1XqOqQjYZc50ZeYvFR1w1VnwEQZDs7HQjyb1y6auWjkkFyfNhZlE/8P/LoRRog4hLQN74gFFN1v00UpwzIXA0/1avvgidlndd2PmnuqFGq9zMCrzuEZj1Wk9qtVtTcSV/O5XQFCRF2LRkCu+lJ7J3Jw0P3hphh5D5axAwl+fLBFzAwvR4DADmdx1bvIR+4ag//RDp2DebCmr1eyFArmw7MXrtLn3AgMBAAGjJzAlMCMGA1UdJQQcMBoGCCsGAQUFBwMBBggrBgEFBQcDAgYEVR0lADANBgkqhkiG9w0BAQsFAAOCAQEAeSvHTBmJLQVFiByicMPxRkV8Ssnr95bSLVC5akiRKBeZShQ1SGrF5qPwDsgGo8Et0BsgKC12LxOIDhUasD+jHWel8Vza8KRMsqy7dFqeH5ZgMymGwzXA/Gbu6UBTE9NQPw2TfhDs6b93Do3y6GnBjEMmozNJAGufOGu69145vcNl3qlL3NN4Q5JgiG6iDGzMGxubwF/SNUhXfkEKjPu+MUXp1n98Hbbob0RwbGVO4RDk1HkSI9VBPolLnkiuzxZFezllgqEvBoxdqy4eFhawv+oY11zgp7wNwwOgQpgX3GekKFb2V+X/VnawOo4Pg9+KiAWQXo7SqKphPcl5jiVCrw==',
],
n:
'mct2nzaIDwkWfyP2h4XtnbCzuqkVNP9rz7zstMvAPYAMxisfVzFmo_FySLEWN-EFJg4iu0x4YjgSlTU2-YXEpPeZbL6EOxBWhIPicZkvFrL89p_0pp6G_RXPvtV6jqkI2GXOdGXmLxUdcNVZ8BEGQ7Ox0I8m9cumrlo5JBcnzYWZRP_D_y6EUaIOIS0De-IBRTdb9NFKcMyFwNP9Wr74InZZ3Xdj5p7qhRqvczAq87hGY9VpParVbU3ElfzuV0BQkRdi0ZArvpSeydycND94aYYeQ-WsQMJfnywRcwML0eAwA5ncdW7yEfuGoP_0Q6dg3mwpq9XshQK5sOzF67S59w',
e: 'AQAB',
},
],
}

const INIT_STATE = {
jwks: jwks_config,
loading: false,
}
const store = createStore(
combineReducers({
jwksReducer: (state = INIT_STATE) => state,
noReducer: (state = {}) => state,
}),
)

const Wrapper = ({ children }) => (
<I18nextProvider i18n={i18n}>
<Provider store={store}>{children}</Provider>
</I18nextProvider>
)

it('Should render jwks page properly', () => {
render(<JwksPage />, {
wrapper: Wrapper,
})
expect(screen.getByText(/JSON Web Keys/)).toBeInTheDocument()
expect(screen.getByTestId('x5c')).toHaveValue(String(jwks_config.keys[0].x5c))
expect(screen.getByTestId('kid')).toHaveValue(jwks_config.keys[0].kid)
expect(screen.getByTestId('kty')).toHaveValue(jwks_config.keys[0].kty)
expect(screen.getByTestId('use')).toHaveValue(jwks_config.keys[0].use)
expect(screen.getByTestId('alg')).toHaveValue(jwks_config.keys[0].alg)
expect(screen.getByTestId('exp')).toHaveValue(String(jwks_config.keys[0].exp))
})
56 changes: 56 additions & 0 deletions plugins/auth-server/components/Configuration/Keys/KeysPage.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import React from 'react'
import { render, screen } from '@testing-library/react'
import KeysPage from './KeysPage'
import { combineReducers, createStore } from 'redux'
import { Provider } from 'react-redux'
import i18n from '../../../../../app/i18n'
import { I18nextProvider } from 'react-i18next'

const jwks_config = {
keys: [
{
kid: 'da42021d-a00d-4c39-a3e7-828f96045269_sig_rs256',
kty: 'RSA',
use: 'sig',
alg: 'RS256',
exp: 1636569490123,
x5c: [
'MIIDCTCCAfGgAwIBAgIgR4Vwlqjkzg6kyd6Hl4FzlLwfZgJJXcN7M7hX2DDOo20wDQYJKoZIhvcNAQELBQAwJDEiMCAGA1UEAwwZSmFucyBBdXRoIENBIENlcnRpZmljYXRlczAeFw0yMTExMDgxNzM4MDBaFw0yMTExMTAxODM4MTBaMCQxIjAgBgNVBAMMGUphbnMgQXV0aCBDQSBDZXJ0aWZpY2F0ZXMwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCZy3afNogPCRZ/I/aHhe2dsLO6qRU0/2vPvOy0y8A9gAzGKx9XMWaj8XJIsRY34QUmDiK7THhiOBKVNTb5hcSk95lsvoQ7EFaEg+JxmS8Wsvz2n/Smnob9Fc++1XqOqQjYZc50ZeYvFR1w1VnwEQZDs7HQjyb1y6auWjkkFyfNhZlE/8P/LoRRog4hLQN74gFFN1v00UpwzIXA0/1avvgidlndd2PmnuqFGq9zMCrzuEZj1Wk9qtVtTcSV/O5XQFCRF2LRkCu+lJ7J3Jw0P3hphh5D5axAwl+fLBFzAwvR4DADmdx1bvIR+4ag//RDp2DebCmr1eyFArmw7MXrtLn3AgMBAAGjJzAlMCMGA1UdJQQcMBoGCCsGAQUFBwMBBggrBgEFBQcDAgYEVR0lADANBgkqhkiG9w0BAQsFAAOCAQEAeSvHTBmJLQVFiByicMPxRkV8Ssnr95bSLVC5akiRKBeZShQ1SGrF5qPwDsgGo8Et0BsgKC12LxOIDhUasD+jHWel8Vza8KRMsqy7dFqeH5ZgMymGwzXA/Gbu6UBTE9NQPw2TfhDs6b93Do3y6GnBjEMmozNJAGufOGu69145vcNl3qlL3NN4Q5JgiG6iDGzMGxubwF/SNUhXfkEKjPu+MUXp1n98Hbbob0RwbGVO4RDk1HkSI9VBPolLnkiuzxZFezllgqEvBoxdqy4eFhawv+oY11zgp7wNwwOgQpgX3GekKFb2V+X/VnawOo4Pg9+KiAWQXo7SqKphPcl5jiVCrw==',
],
n:
'mct2nzaIDwkWfyP2h4XtnbCzuqkVNP9rz7zstMvAPYAMxisfVzFmo_FySLEWN-EFJg4iu0x4YjgSlTU2-YXEpPeZbL6EOxBWhIPicZkvFrL89p_0pp6G_RXPvtV6jqkI2GXOdGXmLxUdcNVZ8BEGQ7Ox0I8m9cumrlo5JBcnzYWZRP_D_y6EUaIOIS0De-IBRTdb9NFKcMyFwNP9Wr74InZZ3Xdj5p7qhRqvczAq87hGY9VpParVbU3ElfzuV0BQkRdi0ZArvpSeydycND94aYYeQ-WsQMJfnywRcwML0eAwA5ncdW7yEfuGoP_0Q6dg3mwpq9XshQK5sOzF67S59w',
e: 'AQAB',
},
],
}

const INIT_STATE = {
jwks: jwks_config,
loading: false,
}

const store = createStore(
combineReducers({
jwksReducer: (state = INIT_STATE) => state,
noReducer: (state = {}) => state,
}),
)

const Wrapper = ({ children }) => (
<I18nextProvider i18n={i18n}>
<Provider store={store}>{children}</Provider>
</I18nextProvider>
)

it('Should render keys page properly', () => {
render(<KeysPage />, {
wrapper: Wrapper,
})
expect(screen.getByText(/JSON Web Keys/)).toBeInTheDocument()
expect(screen.getByTestId('x5c')).toHaveValue(String(jwks_config.keys[0].x5c))
expect(screen.getByTestId('kid')).toHaveValue(jwks_config.keys[0].kid)
expect(screen.getByTestId('kty')).toHaveValue(jwks_config.keys[0].kty)
expect(screen.getByTestId('use')).toHaveValue(jwks_config.keys[0].use)
expect(screen.getByTestId('alg')).toHaveValue(jwks_config.keys[0].alg)
expect(screen.getByTestId('exp')).toHaveValue(String(jwks_config.keys[0].exp))
})

0 comments on commit ea4d016

Please sign in to comment.