use of org.graylog.shaded.elasticsearch7.org.apache.http.ProtocolVersion in project gocd by gocd.
the class SslInfrastructureServiceTest method shouldPassUUIDAndTokenDuringAgentRegistration.
@Test
void shouldPassUUIDAndTokenDuringAgentRegistration() throws Exception {
final ArgumentCaptor<HttpEntityEnclosingRequestBase> httpRequestBaseArgumentCaptor = ArgumentCaptor.forClass(HttpEntityEnclosingRequestBase.class);
when(agentRegistry.uuid()).thenReturn("some-uuid");
when(agentRegistry.token()).thenReturn("some-token");
when(httpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("https", 1, 2), 200, null));
when(httpResponse.getEntity()).thenReturn(new StringEntity(""));
when(httpClient.execute(httpRequestBaseArgumentCaptor.capture())).thenReturn(httpResponse);
sslInfrastructureService.createSslInfrastructure();
sslInfrastructureService.registerIfNecessary(new AgentAutoRegistrationPropertiesImpl(new File("foo", "bar")));
final HttpEntityEnclosingRequestBase httpRequestBase = httpRequestBaseArgumentCaptor.getValue();
final List<NameValuePair> nameValuePairs = URLEncodedUtils.parse(httpRequestBase.getEntity());
assertThat(findParam(nameValuePairs, "uuid").getValue(), is("some-uuid"));
assertThat(findParam(nameValuePairs, "token").getValue(), is("some-token"));
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.ProtocolVersion in project gocd by gocd.
the class RemoteRegistrationRequesterTest method shouldPassAllParametersToPostForRegistrationOfNonElasticAgent.
@Test
void shouldPassAllParametersToPostForRegistrationOfNonElasticAgent() throws IOException {
String url = "http://cruise.com/go";
GoAgentServerHttpClient httpClient = mock(GoAgentServerHttpClient.class);
final CloseableHttpResponse response = mock(CloseableHttpResponse.class);
final ProtocolVersion protocolVersion = new ProtocolVersion("https", 1, 2);
when(response.getStatusLine()).thenReturn(new BasicStatusLine(protocolVersion, HttpStatus.OK.value(), null));
when(response.getEntity()).thenReturn(new StringEntity(""));
when(httpClient.execute(isA(HttpRequestBase.class))).thenReturn(response);
final DefaultAgentRegistry defaultAgentRegistry = new DefaultAgentRegistry();
Properties properties = new Properties();
properties.put(AgentAutoRegistrationPropertiesImpl.AGENT_AUTO_REGISTER_KEY, "t0ps3cret");
properties.put(AgentAutoRegistrationPropertiesImpl.AGENT_AUTO_REGISTER_RESOURCES, "linux, java");
properties.put(AgentAutoRegistrationPropertiesImpl.AGENT_AUTO_REGISTER_ENVIRONMENTS, "uat, staging");
properties.put(AgentAutoRegistrationPropertiesImpl.AGENT_AUTO_REGISTER_HOSTNAME, "agent01.example.com");
remoteRegistryRequester(url, httpClient, defaultAgentRegistry, 200).requestRegistration("cruise.com", new AgentAutoRegistrationPropertiesImpl(null, properties));
verify(httpClient).execute(argThat(hasAllParams(defaultAgentRegistry.uuid(), "", "")));
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.ProtocolVersion in project gocd by gocd.
the class TokenRequesterTest method shouldGetTokenFromServer.
@Test
void shouldGetTokenFromServer() throws Exception {
final ArgumentCaptor<HttpRequestBase> argumentCaptor = ArgumentCaptor.forClass(HttpRequestBase.class);
final CloseableHttpResponse httpResponse = mock(CloseableHttpResponse.class);
when(agentRegistry.uuid()).thenReturn("agent-uuid");
when(httpClient.execute(any(HttpRequestBase.class))).thenReturn(httpResponse);
when(httpResponse.getEntity()).thenReturn(new StringEntity("token-from-server"));
when(httpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("https", 1, 2), SC_OK, null));
final String token = tokenRequester.getToken();
verify(httpClient).execute(argumentCaptor.capture());
final HttpRequestBase requestBase = argumentCaptor.getValue();
final List<NameValuePair> nameValuePairs = URLEncodedUtils.parse(requestBase.getURI(), StandardCharsets.UTF_8);
assertThat(token).isEqualTo("token-from-server");
assertThat(findParam(nameValuePairs, "uuid").getValue()).isEqualTo("agent-uuid");
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.ProtocolVersion in project graylog2-server by Graylog2.
the class ElasticsearchFilterDeprecationWarningsInterceptorTest method testInterceptorSingleHeader.
@Test
public void testInterceptorSingleHeader() throws IOException, HttpException {
ElasticsearchFilterDeprecationWarningsInterceptor interceptor = new ElasticsearchFilterDeprecationWarningsInterceptor();
HttpResponse response = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("HTTP", 0, 0), 0, null));
response.addHeader("Test", "This header should not trigger the interceptor.");
interceptor.process(response, null);
assertThat(response.getAllHeaders()).as("Number of Headers should be unchanged.").hasSize(1);
assertThat(response.getAllHeaders()[0].getName()).as("Remaining Header should be same as the given.").isEqualTo("Test");
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.ProtocolVersion in project graylog2-server by Graylog2.
the class ElasticsearchFilterDeprecationWarningsInterceptorTest method testInterceptorMultipleHeaderFilteredWarningAndMultipleTriggers.
@Test
public void testInterceptorMultipleHeaderFilteredWarningAndMultipleTriggers() throws IOException, HttpException {
ElasticsearchFilterDeprecationWarningsInterceptor interceptor = new ElasticsearchFilterDeprecationWarningsInterceptor();
HttpResponse response = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("HTTP", 0, 0), 0, null));
response.addHeader("Test", "This header should not trigger the interceptor.");
response.addHeader("Warning", "This warning should not trigger the interceptor.");
response.addHeader("Warning", "This text contains the trigger: but in a future major version, direct access to system indices and their aliases will not be allowed - and should be filtered out");
response.addHeader("Warning", "This text contains the trigger: setting was deprecated in Elasticsearch - and should be filtered out");
assertThat(response.getAllHeaders()).as("Number of Headers should be 4 before start.").hasSize(4);
interceptor.process(response, null);
assertThat(response.getAllHeaders()).as("Number of Headers should be 2 less after running the interceptor.").hasSize(2);
}
Aggregations