use of com.thoughtworks.go.config.ServerConfig in project gocd by gocd.
the class ArtifactsDiskCleanerTest method setUp.
@Before
public void setUp() throws Exception {
sysEnv = mock(SystemEnvironment.class);
serverConfig = new ServerConfig();
goConfigService = mock(GoConfigService.class);
when(goConfigService.serverConfig()).thenReturn(serverConfig);
stageService = mock(StageService.class);
when(goConfigService.serverConfig()).thenReturn(serverConfig);
artifactService = mock(ArtifactsService.class);
diskSpaceChecker = mock(SystemDiskSpaceChecker.class);
configDbStateRepository = mock(ConfigDbStateRepository.class);
artifactsDiskCleaner = new ArtifactsDiskCleaner(sysEnv, goConfigService, diskSpaceChecker, artifactService, stageService, configDbStateRepository);
}
use of com.thoughtworks.go.config.ServerConfig in project gocd by gocd.
the class AgentRegistrationControllerTest method shouldNotAutoRegisterAgentIfKeysDoNotMatch.
@Test
public void shouldNotAutoRegisterAgentIfKeysDoNotMatch() throws Exception {
String uuid = "uuid";
when(goConfigService.hasAgent(uuid)).thenReturn(false);
ServerConfig serverConfig = mockedServerConfig("token-generation-key", "someKey");
when(goConfigService.serverConfig()).thenReturn(serverConfig);
when(agentService.agentUsername(uuid, request.getRemoteAddr(), "host")).thenReturn(new Username("some-agent-login-name"));
controller.agentRequest("host", uuid, "location", "233232", "osx", "", "", "", "", "", "", false, token(uuid, serverConfig.getTokenGenerationKey()), request);
verify(agentService).requestRegistration(new Username("some-agent-login-name"), AgentRuntimeInfo.fromServer(new AgentConfig(uuid, "host", request.getRemoteAddr()), false, "location", 233232L, "osx", false));
verify(goConfigService, never()).updateConfig(any(UpdateConfigCommand.class));
}
use of com.thoughtworks.go.config.ServerConfig in project gocd by gocd.
the class AgentRegistrationControllerTest method shouldGenerateToken.
@Test
public void shouldGenerateToken() throws Exception {
final ServerConfig serverConfig = mockedServerConfig("agent-auto-register-key", "someKey");
when(goConfigService.serverConfig()).thenReturn(serverConfig);
when(agentService.findAgent("uuid-from-agent")).thenReturn(AgentInstanceMother.idle());
when(goConfigService.hasAgent("uuid-from-agent")).thenReturn(false);
final ResponseEntity responseEntity = controller.getToken("uuid-from-agent");
assertThat(responseEntity.getStatusCode(), is(HttpStatus.OK));
assertThat(responseEntity.getBody(), is("JCmJaW6YbEA4fIUqf8L9lRV81ua10wV+wRYOFdaBLcM="));
}
use of com.thoughtworks.go.config.ServerConfig in project gocd by gocd.
the class AgentRegistrationControllerTest method shouldAutoRegisterAgentWithHostnameFromAutoRegisterProperties.
@Test
public void shouldAutoRegisterAgentWithHostnameFromAutoRegisterProperties() throws Exception {
String uuid = "uuid";
when(goConfigService.hasAgent(uuid)).thenReturn(false);
ServerConfig serverConfig = mockedServerConfig("token-generation-key", "someKey");
when(goConfigService.serverConfig()).thenReturn(serverConfig);
when(agentService.agentUsername(uuid, request.getRemoteAddr(), "autoregister-hostname")).thenReturn(new Username("some-agent-login-name"));
when(agentConfigService.updateAgent(any(UpdateConfigCommand.class), eq(uuid), any(HttpOperationResult.class), eq(new Username("some-agent-login-name")))).thenReturn(new AgentConfig(uuid, "autoregister-hostname", request.getRemoteAddr()));
controller.agentRequest("host", uuid, "location", "233232", "osx", "someKey", "", "", "autoregister-hostname", "", "", false, token(uuid, serverConfig.getTokenGenerationKey()), request);
verify(agentService).requestRegistration(new Username("some-agent-login-name"), AgentRuntimeInfo.fromServer(new AgentConfig(uuid, "autoregister-hostname", request.getRemoteAddr()), false, "location", 233232L, "osx", false));
verify(agentConfigService).updateAgent(any(UpdateConfigCommand.class), eq(uuid), any(HttpOperationResult.class), eq(new Username("some-agent-login-name")));
}
use of com.thoughtworks.go.config.ServerConfig in project gocd by gocd.
the class AgentRegistrationControllerTest method mockedServerConfig.
private ServerConfig mockedServerConfig(String tokenGenerationKey, String agentAutoRegisterKey) {
final ServerConfig serverConfig = mock(ServerConfig.class);
when(serverConfig.getTokenGenerationKey()).thenReturn(tokenGenerationKey);
when(serverConfig.getAgentAutoRegisterKey()).thenReturn(agentAutoRegisterKey);
when(serverConfig.shouldAutoRegisterAgentWith(agentAutoRegisterKey)).thenReturn(true);
when(serverConfig.security()).thenReturn(new SecurityConfig());
return serverConfig;
}
Aggregations