Redirect warning in compaction

This commit is contained in:
Xavi Aracil 2022-11-24 13:51:04 +01:00
parent 0ba347d8f0
commit a629fc8372
2 changed files with 41 additions and 23 deletions

View File

@ -41,19 +41,12 @@ public class JsonLDCompactionProve extends Probe<Credential> {
compactApi.options(new JsonLdOptions(new CachingDocumentLoader(localDomains)));
JsonObject compactedObject = compactApi.get();
// TODO: Handle mismatch between URL node source and declared ID.
// Handle mismatch between URL node source and declared ID.
if (compactedObject.get("id") != null && crd.getResource().getID() != null
&& !compactedObject.get("id").toString().equals(crd.getResource().getID())) {
// TODO: warning!!
// report_message(
// "Node fetched from source {} declared its id as {}".format(
// task_meta['node_id'], node_id), MESSAGE_LEVEL_WARNING, success=False
// ),
return warning("Node fetched from source " + crd.getResource().getID() + " declared its id as " + compactedObject.get("id").toString(), ctx);
}
return success(this, ctx);
} catch (Exception e) {
return fatal("Error while parsing credential: " + e.getMessage(), ctx);
}

View File

@ -2,11 +2,13 @@ package org.oneedtech.inspect.vc;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.oneedtech.inspect.test.Assertions.assertValid;
import static org.oneedtech.inspect.test.Assertions.assertWarning;
import java.net.URI;
import java.net.URISyntaxException;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.oneedtech.inspect.core.Inspector.Behavior;
import org.oneedtech.inspect.core.report.Report;
@ -22,7 +24,7 @@ public class OB20Tests {
validator = new TestBuilder()
.add(new URI("https://www.example.org/"), "ob20/assets")
.set(Behavior.TEST_INCLUDE_SUCCESS, true)
.set(Behavior.TEST_INCLUDE_WARNINGS, true)
.set(Behavior.TEST_INCLUDE_WARNINGS, false)
.set(Behavior.VALIDATOR_FAIL_FAST, true)
.set(OB20Inspector.Behavior.ALLOW_LOCAL_REDIRECTION, true)
.build();
@ -36,4 +38,27 @@ public class OB20Tests {
assertValid(report);
});
}
@Nested
static class WarningTests {
@BeforeAll
static void setup() throws URISyntaxException {
validator = new TestBuilder()
.add(new URI("https://www.example.org/"), "ob20/assets")
.set(Behavior.TEST_INCLUDE_SUCCESS, true)
.set(Behavior.TEST_INCLUDE_WARNINGS, true)
.set(Behavior.VALIDATOR_FAIL_FAST, true)
.set(OB20Inspector.Behavior.ALLOW_LOCAL_REDIRECTION, true)
.build();
}
@Test
void testWarningRedirectionJsonValid() {
assertDoesNotThrow(()->{
Report report = validator.run(Samples.OB20.JSON.WARNING_REDIRECTION_ASSERTION_JSON.asFileResource());
if(verbose) PrintHelper.print(report, true);
assertWarning(report);
});
}
}
}