This repository has been archived by the owner on Jan 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
/
VarzEndpointIntegrationTests.java
77 lines (62 loc) · 2.38 KB
/
VarzEndpointIntegrationTests.java
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
* Cloud Foundry 2012.02.03 Beta
* Copyright (c) [2009-2012] VMware, Inc. All Rights Reserved.
*
* This product is licensed to you under the Apache License, Version 2.0 (the "License").
* You may not use this product except in compliance with the License.
*
* This product includes a number of subcomponents with
* separate copyright notices and license terms. Your use of these
* subcomponents is subject to the terms and conditions of the
* subcomponent's license, as noted in the LICENSE file.
*/
package org.cloudfoundry.identity.uaa.login.integration;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.cloudfoundry.identity.uaa.integration.UaaTestAccounts;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.crypto.codec.Base64;
/**
* @author Dave Syer
*/
public class VarzEndpointIntegrationTests {
@Rule
public ServerRunning serverRunning = ServerRunning.isRunning();
private UaaTestAccounts testAccounts = UaaTestAccounts.standard(serverRunning);
@Before
public void checkVcap() {
// If running against vcap we don't know the varz password
Assume.assumeTrue(!testAccounts.isProfileActive("vcap"));
}
/**
* tests a happy-day flow of the <code>/varz</code> endpoint
*/
@Test
public void testHappyDay() throws Exception {
HttpHeaders headers = new HttpHeaders();
headers.add("Authorization", testAccounts.getVarzAuthorizationHeader());
ResponseEntity<String> response = serverRunning.getForString("/varz", headers);
assertEquals(HttpStatus.OK, response.getStatusCode());
String map = response.getBody();
assertTrue(map.contains("spring.application"));
}
/**
* tests a unauthorized flow of the <code>/varz</code> endpoint
*/
@Test
public void testUnauthorized() throws Exception {
HttpHeaders headers = new HttpHeaders();
headers.add("Authorization", String.format("Basic %s", new String(Base64.encode("varz:bogus".getBytes()))));
ResponseEntity<String> response = serverRunning.getForString("/varz", headers);
assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode());
String map = response.getBody();
// System.err.println(map);
assertTrue(map.contains("{\"error\""));
}
}