Search in sources :

Example 16 with ServerConfig

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);
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) ServerConfig(com.thoughtworks.go.config.ServerConfig) Before(org.junit.Before)

Example 17 with ServerConfig

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));
}
Also used : ServerConfig(com.thoughtworks.go.config.ServerConfig) AgentConfig(com.thoughtworks.go.config.AgentConfig) UpdateConfigCommand(com.thoughtworks.go.config.UpdateConfigCommand) Username(com.thoughtworks.go.server.domain.Username) Test(org.junit.Test)

Example 18 with ServerConfig

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="));
}
Also used : ServerConfig(com.thoughtworks.go.config.ServerConfig) ResponseEntity(org.springframework.http.ResponseEntity) Test(org.junit.Test)

Example 19 with ServerConfig

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")));
}
Also used : ServerConfig(com.thoughtworks.go.config.ServerConfig) HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) AgentConfig(com.thoughtworks.go.config.AgentConfig) UpdateConfigCommand(com.thoughtworks.go.config.UpdateConfigCommand) Username(com.thoughtworks.go.server.domain.Username) Test(org.junit.Test)

Example 20 with ServerConfig

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;
}
Also used : ServerConfig(com.thoughtworks.go.config.ServerConfig) SecurityConfig(com.thoughtworks.go.config.SecurityConfig)

Aggregations

ServerConfig (com.thoughtworks.go.config.ServerConfig)29 Test (org.junit.Test)16 BasicCruiseConfig (com.thoughtworks.go.config.BasicCruiseConfig)12 CruiseConfig (com.thoughtworks.go.config.CruiseConfig)11 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)6 Username (com.thoughtworks.go.server.domain.Username)5 AgentConfig (com.thoughtworks.go.config.AgentConfig)4 SecurityConfig (com.thoughtworks.go.config.SecurityConfig)4 File (java.io.File)4 ResponseEntity (org.springframework.http.ResponseEntity)4 UpdateConfigCommand (com.thoughtworks.go.config.UpdateConfigCommand)3 ServerSiteUrlConfig (com.thoughtworks.go.domain.ServerSiteUrlConfig)3 Before (org.junit.Before)3 HttpOperationResult (com.thoughtworks.go.server.service.result.HttpOperationResult)2 Stage (com.thoughtworks.go.domain.Stage)1 GoPluginExtension (com.thoughtworks.go.plugin.access.common.settings.GoPluginExtension)1 PluginRequestProcessorRegistry (com.thoughtworks.go.plugin.infra.PluginRequestProcessorRegistry)1 SendEmailMessage (com.thoughtworks.go.server.messaging.SendEmailMessage)1 ServerHealthStateOperationResult (com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult)1