brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From duncangrant <...@git.apache.org>
Subject [GitHub] brooklyn-server pull request #790: Adds HttpFeed.preemptiveBasicAuth
Date Fri, 04 Aug 2017 08:53:48 GMT
Github user duncangrant commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/790#discussion_r131342918
  
    --- Diff: core/src/test/java/org/apache/brooklyn/feed/http/HttpFeedTest.java ---
    @@ -360,7 +364,90 @@ public void testPollsMultiClearsOnSubsequentFailure() throws Exception
{
             
             server.shutdown();
         }
    +    
    +    @Test
    +    public void testPreemptiveBasicAuth() throws Exception {
    +        final String username = "brooklyn";
    +        final String password = "hunter2";
    +
    +        feed = HttpFeed.builder()
    +                .entity(entity)
    +                .baseUrl(server.getUrl("/"))
    +                .credentials(username, password)
    +                .preemptiveBasicAuth(true)
    +                .poll(new HttpPollConfig<Integer>(SENSOR_INT)
    +                        .period(100)
    +                        .onSuccess(HttpValueFunctions.responseCode())
    +                        .onException(Functions.constant(-1)))
    +                .build();
    +
    +        EntityAsserts.assertAttributeEqualsEventually(entity, SENSOR_INT, 200);
    +        RecordedRequest req = server.takeRequest();
    +        String headerVal = req.getHeader("Authorization");
    +        String expectedVal = getBasicAuthHeaderVal(username, password);
    +        assertEquals(headerVal, expectedVal);
    +    }
    +
    +    @Test
    +    public void testPreemptiveBasicAuthFailsIfNoCredentials() throws Exception {
    +        try {
    +            feed = HttpFeed.builder()
    +                    .entity(entity)
    +                    .baseUrl(new URL("http://shouldNeverBeCalled.org"))
    +                    .preemptiveBasicAuth(true)
    +                    .poll(new HttpPollConfig<Integer>(SENSOR_INT)
    +                            .period(100)
    +                            .onSuccess(HttpValueFunctions.responseCode())
    +                            .onException(Functions.constant(-1)))
    +                    .build();
    +            Asserts.shouldHaveFailedPreviously();
    +        } catch (IllegalArgumentException e) {
    +            Asserts.expectedFailureContains(e, "Must not enable preemptiveBasicAuth when
there are no credentials");
    +        }
    +    }
     
    +    // Expected behaviour of o.a.http.client is that it first sends the request without
credentials,
    +    // and then when given a challenge for basic-auth it re-sends the request with the
basic-auth header.
    +    @Test
    +    public void testNonPreemptiveBasicAuth() throws Exception {
    +        final String username = "brooklyn";
    +        final String password = "hunter2";
    +        
    +        if (server != null) server.shutdown();
    --- End diff --
    
    The mock server stuff in this file is in a bit of a mess.  I'd suggest we clean it up
but not in this PR.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message