Skip to content

Commit

Permalink
Bugfix: PUSH contains two different json attributes related to use as…
Browse files Browse the repository at this point in the history
… NameID
  • Loading branch information
oharsta committed Jun 19, 2024
1 parent 76c8375 commit 323d5d8
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
20 changes: 13 additions & 7 deletions manage-gui/src/components/metadata/ARP.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export default class ARP extends React.Component {
if (arpConf.multiplicity) {
this.setState({addInput: true, keyForNewInput: key});
} else {
this.onChange(key, [{value: "*", source: "idp", motivation: "", releaseAs: "", useAsNameId: false}]);
this.onChange(key, [{value: "*", source: "idp", motivation: "", release_as: "", use_as_nameid: false}]);
this.setState({newArpAttributeAddedKey: key});
}
};
Expand All @@ -110,9 +110,15 @@ export default class ARP extends React.Component {
} else {
const currentArpValues = [...this.props.arp.attributes[key] || []];
const motivation = this.getArpAttribute(currentArpValues, "motivation");
const releaseAs = this.getArpAttribute(currentArpValues, "release_as");
const useAsNameId = this.getArpAttribute(currentArpValues, "use_as_name_id", true);
currentArpValues.push({value: value, source: "idp", motivation: motivation, releaseAs: releaseAs, useAsNameId:useAsNameId});
const release_as = this.getArpAttribute(currentArpValues, "release_as");
const use_as_nameid = this.getArpAttribute(currentArpValues, "use_as_nameid", true);
currentArpValues.push({
value: value,
source: "idp",
motivation: motivation,
release_as: release_as,
use_as_nameid: use_as_nameid
});
this.setState({addInput: false, keyForNewInput: undefined, value: "", newArpAttributeAddedKey: key});
this.onChange(key, currentArpValues);
}
Expand All @@ -121,7 +127,7 @@ export default class ARP extends React.Component {
arpAttributeChange = (key, attribute, boolean = false) => e => {
const value = boolean ? e.target.checked : e.target.value;
const {attributes :arpAttributes} = this.props.arp;
if (attribute === "use_as_name_id") {
if (attribute === "use_as_nameid") {
const newArpAttributes = {...arpAttributes};
Object.keys(newArpAttributes).forEach(arpKey => {
arpAttributes[arpKey].forEach(arpValue => {
Expand Down Expand Up @@ -290,8 +296,8 @@ export default class ARP extends React.Component {
colSpan={2}>{I18n.t("arp.new_attribute_use_as_nameid", {key: this.nameOfKey(display, attributeKey)})}</td>
<td colSpan={3}>
<CheckBox name={attributeKey}
onChange={this.arpAttributeChange(attributeKey, "use_as_name_id", true)}
value={this.getArpAttribute(attributeValues, "use_as_name_id", true)}/>
onChange={this.arpAttributeChange(attributeKey, "use_as_nameid", true)}
value={this.getArpAttribute(attributeValues, "use_as_nameid", true)}/>
</td>
</tr>}
</tbody>)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import manage.AbstractIntegrationTest;
import org.junit.Test;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static io.restassured.RestAssured.given;
import static org.apache.http.HttpStatus.SC_OK;
Expand All @@ -12,6 +14,7 @@
public class DatabaseControllerTest extends AbstractIntegrationTest {

@Test
@SuppressWarnings("unchecked")
public void pushPreview() throws Exception {
Map connections = given()
.when()
Expand All @@ -30,6 +33,17 @@ public void pushPreview() throws Exception {
.get("coin"))
.get("imported_from_edugain");
assertEquals(importFromEdugain, "1");

//ensure the correct ARP is exported
List<Map<String, Object>> arpGivenNames = (List<Map<String, Object>>) ((Map) ((Map) ((Map) connections.get("connections"))
.get("11"))
.get("arp_attributes"))
.get("urn:mace:dir:attribute-def:givenName");
Map<String, Object> arpGivenName = arpGivenNames.get(0);
List<String> keys = arpGivenName.keySet().stream().sorted().collect(Collectors.toList());
assertEquals(List.of("motivation", "release_as", "use_as_nameid", "value"), keys);
assertEquals("aliasGivenName", arpGivenName.get("release_as"));
assertEquals(true, arpGivenName.get("use_as_nameid"));
}

}
4 changes: 3 additions & 1 deletion manage-server/src/test/resources/json/meta_data_seed.json
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,9 @@
{
"source": "idp",
"value": "*",
"motivation": "1234"
"motivation": "1234",
"release_as": "aliasGivenName",
"use_as_nameid": true
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"urn:mace:dir:attribute-def:givenName": [
{
"value": "*",
"motivation": "1234"
"motivation": "1234",
"release_as": "aliasGivenName",
"use_as_nameid": true
}
]
},
Expand Down

0 comments on commit 323d5d8

Please sign in to comment.