use of org.springframework.util.LinkedMultiValueMap in project gocd by gocd.
the class ElasticAgentRequestProcessorTest method shouldProcessListAgentRequest.
@Test
public void shouldProcessListAgentRequest() throws Exception {
LinkedMultiValueMap<String, ElasticAgentMetadata> allAgents = new LinkedMultiValueMap<>();
ElasticAgentMetadata agent = new ElasticAgentMetadata("foo", "bar", "docker", AgentRuntimeStatus.Building, AgentConfigStatus.Disabled);
allAgents.put("docker", Arrays.asList(agent));
when(agentService.allElasticAgents()).thenReturn(allAgents);
GoApiResponse response = processor.process(pluginDescriptor, new DefaultGoApiRequest(REQUEST_SERVER_LIST_AGENTS, "1.0", pluginIdentifier));
JSONAssert.assertEquals("[{\"agent_id\":\"bar\",\"agent_state\":\"Building\",\"build_state\":\"Building\",\"config_state\":\"Disabled\"}]", response.responseBody(), true);
}
use of org.springframework.util.LinkedMultiValueMap in project spring-boot by spring-projects.
the class SampleMethodSecurityApplicationTests method testDenied.
@Test
public void testDenied() throws Exception {
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
MultiValueMap<String, String> form = new LinkedMultiValueMap<>();
form.set("username", "user");
form.set("password", "user");
getCsrf(form, headers);
ResponseEntity<String> entity = this.restTemplate.exchange("/login", HttpMethod.POST, new HttpEntity<>(form, headers), String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND);
String cookie = entity.getHeaders().getFirst("Set-Cookie");
headers.set("Cookie", cookie);
ResponseEntity<String> page = this.restTemplate.exchange(entity.getHeaders().getLocation(), HttpMethod.GET, new HttpEntity<Void>(headers), String.class);
assertThat(page.getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN);
assertThat(page.getBody()).contains("Access denied");
}
use of org.springframework.util.LinkedMultiValueMap in project cas by apereo.
the class RestServiceRegistryConfiguration method restfulServiceRegistry.
@Bean
@RefreshScope
@SneakyThrows
public ServiceRegistry restfulServiceRegistry() {
final ServiceRegistryProperties registry = casProperties.getServiceRegistry();
final RestTemplate restTemplate = new RestTemplate();
final MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
if (StringUtils.isNotBlank(registry.getRest().getBasicAuthUsername()) && StringUtils.isNotBlank(registry.getRest().getBasicAuthPassword())) {
final String auth = registry.getRest().getBasicAuthUsername() + ":" + registry.getRest().getBasicAuthPassword();
final byte[] encodedAuth = EncodingUtils.encodeBase64ToByteArray(auth.getBytes(StandardCharsets.UTF_8));
final String authHeader = "Basic " + new String(encodedAuth, StandardCharsets.UTF_8);
headers.put("Authorization", CollectionUtils.wrap(authHeader));
}
return new RestServiceRegistry(restTemplate, registry.getRest().getUrl(), headers);
}
use of org.springframework.util.LinkedMultiValueMap in project cas by apereo.
the class X509RestHttpRequestCredentialFactoryTests method createX509Credential.
@Test
public void createX509Credential() throws IOException {
final MultiValueMap<String, String> requestBody = new LinkedMultiValueMap<>();
final Scanner scan = new Scanner(new ClassPathResource("ldap-crl.crt").getFile(), StandardCharsets.UTF_8.name());
final String certStr = scan.useDelimiter("\\Z").next();
scan.close();
requestBody.add("cert", certStr);
final Credential cred = factory.fromRequestBody(requestBody).iterator().next();
assertTrue(cred instanceof X509CertificateCredential);
}
use of org.springframework.util.LinkedMultiValueMap in project cas by apereo.
the class X509RestHttpRequestCredentialFactoryTests method createDefaultCredential.
@Test
public void createDefaultCredential() {
final MultiValueMap<String, String> requestBody = new LinkedMultiValueMap<>();
requestBody.add("username", "name");
requestBody.add("password", "passwd");
final Collection cred = factory.fromRequestBody(requestBody);
assertTrue(cred.isEmpty());
}
Aggregations