OIDC mapper bug fixes (#1439)

* mapper bug fixes

* change to toUpperCase()

* update data test id for regex switch

* fix cypress test
This commit is contained in:
Jenny 2021-10-28 10:51:26 -04:00 committed by GitHub
parent 8f5fe27647
commit b80f0a3018
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 37 additions and 13 deletions

View file

@ -19,7 +19,7 @@ export default class AddMapperPage {
private userSessionAttribute = "user-session-attribute"; private userSessionAttribute = "user-session-attribute";
private userSessionAttributeValue = "user-session-attribute-value"; private userSessionAttributeValue = "user-session-attribute-value";
private newMapperSaveButton = "new-mapper-save-button"; private newMapperSaveButton = "new-mapper-save-button";
private regexAttributeValuesSwitch = "regex-attribute-values-switch"; private regexAttributeValuesSwitch = "regex-values-switch";
private syncmodeSelectToggle = "#syncMode"; private syncmodeSelectToggle = "#syncMode";
private attributesKeyInput = 'input[name="config.attributes[0].key"]'; private attributesKeyInput = 'input[name="config.attributes[0].key"]';
private attributesValueInput = 'input[name="config.attributes[0].value"]'; private attributesValueInput = 'input[name="config.attributes[0].value"]';

View file

@ -43,6 +43,10 @@ export type IdPMapperRepresentationWithAttributes =
attributes: KeyValueType[]; attributes: KeyValueType[];
}; };
type Role = RoleRepresentation & {
clientId?: string;
};
export const AddMapper = () => { export const AddMapper = () => {
const { t } = useTranslation("identity-providers"); const { t } = useTranslation("identity-providers");
@ -73,7 +77,11 @@ export const AddMapper = () => {
const [mapperTypes, setMapperTypes] = const [mapperTypes, setMapperTypes] =
useState<Record<string, IdentityProviderMapperRepresentation>>(); useState<Record<string, IdentityProviderMapperRepresentation>>();
const [mapperType, setMapperType] = useState( const [mapperType, setMapperType] = useState(
isSocialIdP ? "attributeImporter" : "hardcodedRole" isSocialIdP
? "attributeImporter"
: providerId === "saml"
? "advancedAttributeToRole"
: "hardcodedUserSessionAttribute"
); );
const [currentMapper, setCurrentMapper] = const [currentMapper, setCurrentMapper] =
@ -185,7 +193,7 @@ export const AddMapper = () => {
const targetOptions = ["local", "brokerId", "brokerUsername"]; const targetOptions = ["local", "brokerId", "brokerUsername"];
const [targetOptionsOpen, setTargetOptionsOpen] = useState(false); const [targetOptionsOpen, setTargetOptionsOpen] = useState(false);
const [selectedRole, setSelectedRole] = useState<RoleRepresentation[]>([]); const [selectedRole, setSelectedRole] = useState<Role[]>([]);
const formValues = form.getValues(); const formValues = form.getValues();
@ -205,8 +213,7 @@ export const AddMapper = () => {
formValues.identityProviderMapper === "oidc-user-attribute-idp-mapper"; formValues.identityProviderMapper === "oidc-user-attribute-idp-mapper";
const isHardcodedAttribute = const isHardcodedAttribute =
form.getValues().identityProviderMapper === formValues.identityProviderMapper === "hardcoded-attribute-idp-mapper";
"hardcoded-attribute-idp-mapper";
const isHardcodedRole = const isHardcodedRole =
formValues.identityProviderMapper === "oidc-hardcoded-role-idp-mapper"; formValues.identityProviderMapper === "oidc-hardcoded-role-idp-mapper";
@ -251,7 +258,9 @@ export const AddMapper = () => {
divider divider
/> />
<AssociatedRolesModal <AssociatedRolesModal
onConfirm={(role) => setSelectedRole(role)} onConfirm={(role: Role[]) => {
setSelectedRole(role);
}}
allRoles={roles} allRoles={roles}
open={rolesModalOpen} open={rolesModalOpen}
omitComposites omitComposites
@ -338,7 +347,11 @@ export const AddMapper = () => {
/> />
</FormGroup> </FormGroup>
<FormGroup <FormGroup
label={t("regexAttributeValues")} label={
isSAMLAdvancedAttrToRole
? t("regexAttributeValues")
: t("regexClaimValues")
}
labelIcon={ labelIcon={
<HelpItem <HelpItem
helpText="identity-providers-help:regexAttributeValues" helpText="identity-providers-help:regexAttributeValues"
@ -351,13 +364,17 @@ export const AddMapper = () => {
fieldId="regexAttributeValues" fieldId="regexAttributeValues"
> >
<Controller <Controller
name="config.are-attribute-values-regex" name={
isOIDCAdvancedClaimToRole
? "config.are-claim-values-regex"
: "config.are-attribute-values-regex"
}
control={control} control={control}
defaultValue="false" defaultValue="false"
render={({ onChange, value }) => ( render={({ onChange, value }) => (
<Switch <Switch
id="regexAttributeValues" id="regexValues"
data-testid="regex-attribute-values-switch" data-testid="regex-values-switch"
label={t("common:on")} label={t("common:on")}
labelOff={t("common:off")} labelOff={t("common:off")}
isChecked={value === "true"} isChecked={value === "true"}
@ -834,7 +851,12 @@ export const AddMapper = () => {
id="kc-role" id="kc-role"
data-testid="mapper-role-input" data-testid="mapper-role-input"
name="config.role" name="config.role"
value={selectedRole[0]?.name} isDisabled={!!id}
value={
selectedRole[0]?.clientRole
? `${selectedRole[0].clientId}.${selectedRole[0]?.name}`
: selectedRole[0]?.name
}
validated={ validated={
errors.config?.role errors.config?.role
? ValidatedOptions.error ? ValidatedOptions.error
@ -844,6 +866,7 @@ export const AddMapper = () => {
<Button <Button
data-testid="select-role-button" data-testid="select-role-button"
onClick={() => toggleModal()} onClick={() => toggleModal()}
isDisabled={!!id}
> >
{t("selectRole")} {t("selectRole")}
</Button> </Button>

View file

@ -91,7 +91,7 @@ export const AddMapperForm = ({
> >
<Controller <Controller
name="config.syncMode" name="config.syncMode"
defaultValue={syncModes[0]} defaultValue={syncModes[0].toUpperCase()}
control={control} control={control}
render={({ onChange, value }) => ( render={({ onChange, value }) => (
<Select <Select
@ -149,7 +149,7 @@ export const AddMapperForm = ({
? `${providerId.toLowerCase()}-user-attribute-mapper` ? `${providerId.toLowerCase()}-user-attribute-mapper`
: providerId === "saml" : providerId === "saml"
? "saml-advanced-role-idp-mapper" ? "saml-advanced-role-idp-mapper"
: "oidc-advanced-role-idp-mapper" : "hardcoded-user-session-attribute-idp-mapper"
} }
control={control} control={control}
render={({ onChange, value }) => ( render={({ onChange, value }) => (

View file

@ -169,6 +169,7 @@ export default {
syncModeOverride: "Sync mode override", syncModeOverride: "Sync mode override",
mapperType: "Mapper type", mapperType: "Mapper type",
regexAttributeValues: "Regex Attribute Values", regexAttributeValues: "Regex Attribute Values",
regexClaimValues: "Regex Claim Values",
selectRole: "Select role", selectRole: "Select role",
mapperCreateSuccess: "Mapper created successfully.", mapperCreateSuccess: "Mapper created successfully.",
mapperCreateError: "Error creating mapper.", mapperCreateError: "Error creating mapper.",