Skip to content

Commit

Permalink
[feature/nro-profile] Check link content type (fixes #31).
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhrr committed Feb 20, 2024
1 parent 5c2a5a7 commit 0bcf292
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ public boolean run(final Context context, final Result proto,
Result nr2 = new Result(nr);
nr2.addNode("value");
context.submitTest(new net.apnic.rdap.conformance.test.common.Link(
value, nr2
value, nr2, null
));
}

String type = Utils.castToString(data.get("type"));
String href = Utils.getStringAttribute(context, nr, "href",
Status.Failure, data);
if (href == null) {
Expand All @@ -61,7 +62,7 @@ public boolean run(final Context context, final Result proto,
Result nr2 = new Result(nr);
nr2.addNode("href");
context.submitTest(new net.apnic.rdap.conformance.test.common.Link(
href, nr2
href, nr2, type
));
}

Expand Down
23 changes: 19 additions & 4 deletions src/main/java/net/apnic/rdap/conformance/test/common/Link.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import net.apnic.rdap.conformance.responsetest.NotStatusCode;
import net.apnic.rdap.conformance.Utils;

import org.apache.http.Header;
import org.apache.http.HttpResponse;
import org.apache.http.HttpRequest;

Expand All @@ -24,6 +25,7 @@
final public class Link implements Test {
private String url;
private Result proto;
private String expectedContentType;
private Context context = null;
private HttpResponse httpResponse = null;
private Throwable throwable = null;
Expand All @@ -34,11 +36,14 @@ final public class Link implements Test {
*
* @param argUrl a {@link java.lang.String} object.
* @param argProto a {@link net.apnic.rdap.conformance.Result} object.
* @param argExpectedContentType a {@link java.lang.String} object.
*/
public Link(final String argUrl,
final Result argProto) {
final Result argProto,
final String argExpectedContentType) {
url = argUrl;
proto = argProto;
expectedContentType = argExpectedContentType;
}

/** {@inheritDoc} */
Expand Down Expand Up @@ -81,9 +86,19 @@ public boolean run() {
context.addResult(r);
ResponseTest sc = new NotStatusCode(0);
boolean scres = sc.run(context, proto, httpResponse);
if (!scres) {
return false;

if (expectedContentType != null) {
Header contentType =
httpResponse.getFirstHeader("Content-Type");
boolean res = contentType.getValue().equals(expectedContentType);

Result r2 = new Result(proto);
r2.setCode("response");
r2.setStatus(res ? Status.Success : Status.Warning);
r2.setInfo("link content type matches received content type");
context.addResult(r2);
}
return true;

return scres;
}
}

0 comments on commit 0bcf292

Please sign in to comment.