예제 #1
0
  @Test(
      groups = {SHOULD},
      description =
          "LDP clients SHOULD use the HTTP If-Match header and HTTP ETags "
              + "to ensure it isn’t modifying a resource that has changed since the "
              + "client last retrieved its representation. LDP servers SHOULD require "
              + "the HTTP If-Match header and HTTP ETags to detect collisions.")
  @SpecTest(
      specRefUri = LdpTestSuite.SPEC_URI + "#ldpr-put-precond",
      testMethod = METHOD.AUTOMATED,
      approval = STATUS.WG_APPROVED,
      comment =
          "Covers only part of the specification requirement. "
              + "testConditionFailedStatusCode, testPreconditionRequiredStatusCode "
              + "and testPutBadETag covers the rest.")
  public void testPutRequiresIfMatch() throws URISyntaxException {
    skipIfMethodNotAllowed(HttpMethod.PUT);

    String resourceUri = getResourceUri();
    Response response =
        buildBaseRequestSpecification()
            .expect()
            .statusCode(isSuccessful())
            .header(ETAG, isValidEntityTag())
            .when()
            .get(resourceUri);

    buildBaseRequestSpecification()
        .contentType(response.getContentType())
        .body(response.asByteArray())
        .expect()
        .statusCode(not(isSuccessful()))
        .when()
        .put(resourceUri);
  }
예제 #2
0
 private Workbook readWorkbookFrom(Response whenPostingToReportUrl) {
   try {
     return WorkbookFactory.create(new ByteArrayInputStream(whenPostingToReportUrl.asByteArray()));
   } catch (IOException | InvalidFormatException e) {
     e.printStackTrace();
     throw new AssertionFailedError(e.getMessage());
   }
 }
예제 #3
0
  @Test(
      groups = {MUST},
      description =
          "LDP servers MUST respond with status code 412 "
              + "(Condition Failed) if ETags fail to match when there "
              + "are no other errors with the request [HTTP11]. LDP "
              + "servers that require conditional requests MUST respond "
              + "with status code 428 (Precondition Required) when the "
              + "absence of a precondition is the only reason for rejecting "
              + "the request [RFC6585].")
  @SpecTest(
      specRefUri = LdpTestSuite.SPEC_URI + "#ldpr-put-precond",
      testMethod = METHOD.AUTOMATED,
      approval = STATUS.WG_APPROVED,
      comment =
          "Covers only part of the specification requirement. "
              + "testPutBadETag, testPreconditionRequiredStatusCode "
              + "and testPutRequiresIfMatch covers the rest.")
  public void testConditionFailedStatusCode() {
    skipIfMethodNotAllowed(HttpMethod.PUT);

    String resourceUri = getResourceUri();
    Response response =
        buildBaseRequestSpecification()
            .expect()
            .statusCode(isSuccessful())
            .header(ETAG, isValidEntityTag())
            .when()
            .get(resourceUri);
    String contentType = response.getContentType();

    buildBaseRequestSpecification()
        .contentType(contentType)
        .header(IF_MATCH, "\"These aren't the ETags you're looking for.\"")
        .body(response.asByteArray())
        .expect()
        .statusCode(HttpStatus.SC_PRECONDITION_FAILED)
        .when()
        .put(resourceUri);
  }
예제 #4
0
  @Test(
      groups = {MUST},
      description =
          "LDP servers MUST respond with status code 412 "
              + "(Condition Failed) if ETags fail to match when there "
              + "are no other errors with the request [HTTP11]. LDP "
              + "servers that require conditional requests MUST respond "
              + "with status code 428 (Precondition Required) when the "
              + "absence of a precondition is the only reason for rejecting "
              + "the request [RFC6585].")
  @SpecTest(
      specRefUri = LdpTestSuite.SPEC_URI + "#ldpr-put-precond",
      testMethod = METHOD.AUTOMATED,
      approval = STATUS.WG_APPROVED,
      comment =
          "Covers only part of the specification requirement. "
              + "testConditionFailedStatusCode,  testPutBadETag"
              + "and testPutRequiresIfMatch covers the rest.")
  public void testPreconditionRequiredStatusCode() {
    skipIfMethodNotAllowed(HttpMethod.PUT);

    String resourceUri = getResourceUri();
    Response getResponse =
        buildBaseRequestSpecification()
            .expect()
            .statusCode(isSuccessful())
            .header(ETAG, isValidEntityTag())
            .when()
            .get(resourceUri);

    // Verify that we can successfully PUT the resource WITH an If-Match header.
    Response ifMatchResponse =
        buildBaseRequestSpecification()
            .header(IF_MATCH, getResponse.getHeader(ETAG))
            .contentType(getResponse.contentType())
            .body(getResponse.asByteArray())
            .when()
            .put(resourceUri);
    if (!isSuccessful().matches(ifMatchResponse.getStatusCode())) {
      throw new SkipException(
          Thread.currentThread().getStackTrace()[1].getMethodName(),
          "Skipping test because PUT request failed with valid If-Match header.",
          skipLog);
    }

    // Now try WITHOUT the If-Match header. If the result is NOT successful,
    // it should be because the header is missing and we can check the error
    // code.
    Response noIfMatchResponse =
        buildBaseRequestSpecification()
            .contentType(getResponse.contentType())
            .body(getResponse.asByteArray())
            .when()
            .put(resourceUri);
    if (isSuccessful().matches(noIfMatchResponse.getStatusCode())) {
      // It worked. This server doesn't require If-Match, which is only a
      // SHOULD requirement (see testPutRequiresIfMatch). Skip the test.
      throw new SkipException(
          Thread.currentThread().getStackTrace()[1].getMethodName(),
          "Server does not require If-Match header.",
          skipLog);
    }

    assertEquals(
        428,
        noIfMatchResponse.getStatusCode(),
        "Expected 428 Precondition Required error on PUT request with no If-Match header");
  }