-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathPagerDutyHttpClientTest.java
More file actions
60 lines (47 loc) · 2.27 KB
/
PagerDutyHttpClientTest.java
File metadata and controls
60 lines (47 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package biz.neustar.pagerduty.util;
import static org.junit.Assert.*;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.AuthState;
import org.apache.http.auth.Credentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.protocol.ClientContext;
import org.apache.http.protocol.HttpContext;
import org.junit.Test;
public class PagerDutyHttpClientTest {
@Test
public void testBasicAuthConstructor() {
AuthScope authScope = new AuthScope("example.pagerduty.com", 443);
PagerDutyHttpClient client = new PagerDutyHttpClient("example", "user", "pass");
CredentialsProvider provider = client.createCredentialsProvider();
assertNotNull(provider);
Credentials creds = provider.getCredentials(authScope);
assertNotNull(creds);
assertEquals("pass", creds.getPassword());
}
@Test
public void testTokenAuthConstructor() {
AuthScope authScope = new AuthScope("example.pagerduty.com", 443);
PagerDutyHttpClient client = new PagerDutyHttpClient("example", "token");
CredentialsProvider provider = client.createCredentialsProvider();
assertNotNull(provider);
Credentials creds = provider.getCredentials(authScope);
assertNotNull(creds);
assertEquals("token", creds.getPassword());
}
@Test
public void testCreateHttpContextTokenAuth() {
AuthScope authScope = new AuthScope("example.pagerduty.com", 443);
PagerDutyHttpClient client = new PagerDutyHttpClient("example", "token");
HttpContext httpContext = client.createHttpContext();
assertNotNull(httpContext);
AuthState state = (AuthState)httpContext.getAttribute(ClientContext.TARGET_AUTH_STATE);
assertNotNull(state.getAuthScheme());
assertTrue(state.getAuthScheme() instanceof TokenAuthScheme);
assertNotNull(state.getAuthScope());
assertEquals(authScope, state.getAuthScope());
assertNotNull(state.getCredentials());
assertTrue(state.getCredentials() instanceof TokenAuthCredentials);
TokenAuthCredentials tokenCreds = (TokenAuthCredentials)state.getCredentials();
assertEquals("token", tokenCreds.getPassword());
}
}