Skip to content

Commit

Permalink
feat: edit op add jwt now defaults value to null. resolves #7
Browse files Browse the repository at this point in the history
  • Loading branch information
mattebit committed Mar 13, 2024
1 parent bfa0854 commit ebca66e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 8 deletions.
8 changes: 4 additions & 4 deletions tool/src/main/java/migt/Module.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,6 @@ public <T extends Module> boolean setResult(T module) {
return module.result;
}

public void setResult(boolean result) {
this.result = result;
}

public void setApplicable(boolean applicable) {
this.applicable = applicable;
}
Expand All @@ -111,6 +107,10 @@ public boolean getResult() {
return this.result & this.applicable;
}

public void setResult(boolean result) {
this.result = result;
}

/**
* Execute this module and give a result
*
Expand Down
7 changes: 5 additions & 2 deletions tool/src/main/java/migt/Tools.java
Original file line number Diff line number Diff line change
Expand Up @@ -754,8 +754,11 @@ public static String editJson(EditOperation.Jwt_action action,
document = jsonPath.set(document, newValue, Configuration.defaultConfiguration());
break;
case ADD:
document = jsonPath.put(document, newKey, newValue, Configuration.defaultConfiguration());
//TODO: check if set also adds in case it is not found
document = jsonPath.put(
document,
newKey,
newValue.isEmpty() ? null : newValue,
Configuration.defaultConfiguration());
break;
case SAVE:
Object to_save = JsonPath.read(content, j_path);
Expand Down
3 changes: 2 additions & 1 deletion tool/src/test/java/DecodeOperation_Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class DecodeOperation_Test {
String input = "{\n" +
Expand Down Expand Up @@ -140,7 +141,7 @@ void test_decode_jwt() throws ParsingException {

dop.loader(op_api);
dop.execute(null);
assertEquals(true, dop.getResult());
assertTrue(dop.getResult());
DecodeOperation_API dop_api = dop.getAPI();
assertEquals("{\"exp\":1710327846,\"iat\":1710325866,\"iss\":\"http://trust-anchor.org:8000\",\"sub\":\"http://trust-anchor.org:8000\",\"jwks\":{\"keys\":[{\"kty\":\"RSA\",\"n\":\"o8IolRjZlkzct-48rhrVlTnYU1pkMbVJD-DU05oMS9RVGrsFypg98m-Kw4H4qNPyQVx2OQORi-xShgk7HU-gK_2pVguYkv06FajL_edEAqqsqt_74Qf2WLRC5pfJG_z9OPzY8JGyk-z3SbeHN_BXKI8GY5E4WU2SstmQ9fyL4CxtRfjUia8limTC_3MOpT3zi5nr03jfbjpnjga51qXurxnlzc3a_xjk5RAApKxUvNwhJ275M0CmB99DjPwF6BLvUgJqgyCpUOn36LOhI4FquVqhqhiwKlMmiMe3yy0yNQ7FXBWxjzhexbpyc3Vu7zFIHPAcC4UyIQhc3waEj2viXw\",\"e\":\"AQAB\",\"kid\":\"BXvfrlnhAMuHR07ajUmAcBRQcSzmw0c_RAgJnpS-9WQ\"}]},\"metadata\":{\"federation_entity\":{\"contacts\":[\"ops@localhost\"],\"federation_fetch_endpoint\":\"http://trust-anchor.org:8000/fetch\",\"federation_resolve_endpoint\":\"http://trust-anchor.org:8000/resolve\",\"federation_trust_mark_status_endpoint\":\"http://trust-anchor.org:8000/trust_mark_status\",\"homepage_uri\":\"http://trust-anchor.org:8000\",\"organization_name\":\"example TA\",\"policy_uri\":\"http://trust-anchor.org:8000/en/website/legal-information\",\"logo_uri\":\"http://trust-anchor.org:8000/static/svg/spid-logo-c-lb.svg\",\"federation_list_endpoint\":\"http://trust-anchor.org:8000/list\"}},\"trust_mark_issuers\":{\"https://www.spid.gov.it/certification/rp/public\":[\"https://registry.spid.agid.gov.it\",\"https://public.intermediary.spid.it\"],\"https://www.spid.gov.it/certification/rp/private\":[\"https://registry.spid.agid.gov.it\",\"https://private.other.intermediary.it\"],\"https://sgd.aa.it/onboarding\":[\"https://sgd.aa.it\"]},\"constraints\":{\"max_path_length\":1}}", dop_api.jwt.payload);
assertEquals("{\"kid\":\"BXvfrlnhAMuHR07ajUmAcBRQcSzmw0c_RAgJnpS-9WQ\",\"typ\":\"entity-statement+jwt\",\"alg\":\"RS256\"}", dop_api.jwt.header);
Expand Down
27 changes: 26 additions & 1 deletion tool/src/test/java/EditOperation_test.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,33 @@ public void test_add_json_jwt() throws ParsingException {
dop.loader(new Operation_API(DecodeOperation_Test.get_test_message_with_jwt(), false));

dop.execute(null);
assertEquals(true, dop.editOperations.get(0).getResult());
assertTrue(dop.editOperations.get(0).getResult());

assertEquals("{\"exp\":1710327846,\"iat\":1710325866,\"iss\":\"http://trust-anchor.org:8000\",\"sub\":\"http://trust-anchor.org:8000\",\"jwks\":{\"keys\":[{\"kty\":\"RSA\",\"n\":\"o8IolRjZlkzct-48rhrVlTnYU1pkMbVJD-DU05oMS9RVGrsFypg98m-Kw4H4qNPyQVx2OQORi-xShgk7HU-gK_2pVguYkv06FajL_edEAqqsqt_74Qf2WLRC5pfJG_z9OPzY8JGyk-z3SbeHN_BXKI8GY5E4WU2SstmQ9fyL4CxtRfjUia8limTC_3MOpT3zi5nr03jfbjpnjga51qXurxnlzc3a_xjk5RAApKxUvNwhJ275M0CmB99DjPwF6BLvUgJqgyCpUOn36LOhI4FquVqhqhiwKlMmiMe3yy0yNQ7FXBWxjzhexbpyc3Vu7zFIHPAcC4UyIQhc3waEj2viXw\",\"e\":\"AQAB\",\"kid\":\"BXvfrlnhAMuHR07ajUmAcBRQcSzmw0c_RAgJnpS-9WQ\"}]},\"metadata\":{\"federation_entity\":{\"contacts\":[\"ops@localhost\"],\"federation_fetch_endpoint\":\"http://trust-anchor.org:8000/fetch\",\"federation_resolve_endpoint\":\"http://trust-anchor.org:8000/resolve\",\"federation_trust_mark_status_endpoint\":\"http://trust-anchor.org:8000/trust_mark_status\",\"homepage_uri\":\"http://trust-anchor.org:8000\",\"organization_name\":\"example TA\",\"policy_uri\":\"http://trust-anchor.org:8000/en/website/legal-information\",\"logo_uri\":\"http://trust-anchor.org:8000/static/svg/spid-logo-c-lb.svg\",\"federation_list_endpoint\":\"http://trust-anchor.org:8000/list\"}},\"trust_mark_issuers\":{\"https://www.spid.gov.it/certification/rp/public\":[\"https://registry.spid.agid.gov.it\",\"https://public.intermediary.spid.it\"],\"https://www.spid.gov.it/certification/rp/private\":[\"https://registry.spid.agid.gov.it\",\"https://private.other.intermediary.it\"],\"https://sgd.aa.it/onboarding\":[\"https://sgd.aa.it\"]},\"constraints\":{\"max_path_length\":1},\"new\":\"valuenew\"}", dop.getAPI().jwt.payload);
}

@Test
public void test_add_json_jwt_null() throws ParsingException {
String input = "{\n" +
" \"from\": \"body\",\n" +
" \"type\": \"jwt\",\n" +
" \"decode regex\": \"[^\\\\n\\\\r]*\",\n" +
" \"edits\": [\n" +
" {\n" +
" \"jwt from\": \"payload\",\n" +
" \"jwt add\": \"$\",\n" +
" \"key\": \"new\",\n" +
" \"value\": \"\"\n" +
" }\n" +
" ]\n" +
"}";

DecodeOperation dop = new DecodeOperation(new JSONObject(input));
dop.loader(new Operation_API(DecodeOperation_Test.get_test_message_with_jwt(), false));

dop.execute(null);
assertTrue(dop.editOperations.get(0).getResult());

assertEquals("{\"exp\":1710327846,\"iat\":1710325866,\"iss\":\"http://trust-anchor.org:8000\",\"sub\":\"http://trust-anchor.org:8000\",\"jwks\":{\"keys\":[{\"kty\":\"RSA\",\"n\":\"o8IolRjZlkzct-48rhrVlTnYU1pkMbVJD-DU05oMS9RVGrsFypg98m-Kw4H4qNPyQVx2OQORi-xShgk7HU-gK_2pVguYkv06FajL_edEAqqsqt_74Qf2WLRC5pfJG_z9OPzY8JGyk-z3SbeHN_BXKI8GY5E4WU2SstmQ9fyL4CxtRfjUia8limTC_3MOpT3zi5nr03jfbjpnjga51qXurxnlzc3a_xjk5RAApKxUvNwhJ275M0CmB99DjPwF6BLvUgJqgyCpUOn36LOhI4FquVqhqhiwKlMmiMe3yy0yNQ7FXBWxjzhexbpyc3Vu7zFIHPAcC4UyIQhc3waEj2viXw\",\"e\":\"AQAB\",\"kid\":\"BXvfrlnhAMuHR07ajUmAcBRQcSzmw0c_RAgJnpS-9WQ\"}]},\"metadata\":{\"federation_entity\":{\"contacts\":[\"ops@localhost\"],\"federation_fetch_endpoint\":\"http://trust-anchor.org:8000/fetch\",\"federation_resolve_endpoint\":\"http://trust-anchor.org:8000/resolve\",\"federation_trust_mark_status_endpoint\":\"http://trust-anchor.org:8000/trust_mark_status\",\"homepage_uri\":\"http://trust-anchor.org:8000\",\"organization_name\":\"example TA\",\"policy_uri\":\"http://trust-anchor.org:8000/en/website/legal-information\",\"logo_uri\":\"http://trust-anchor.org:8000/static/svg/spid-logo-c-lb.svg\",\"federation_list_endpoint\":\"http://trust-anchor.org:8000/list\"}},\"trust_mark_issuers\":{\"https://www.spid.gov.it/certification/rp/public\":[\"https://registry.spid.agid.gov.it\",\"https://public.intermediary.spid.it\"],\"https://www.spid.gov.it/certification/rp/private\":[\"https://registry.spid.agid.gov.it\",\"https://private.other.intermediary.it\"],\"https://sgd.aa.it/onboarding\":[\"https://sgd.aa.it\"]},\"constraints\":{\"max_path_length\":1},\"new\":null}", dop.getAPI().jwt.payload);
}
}

0 comments on commit ebca66e

Please sign in to comment.