コード例 #1
0
  @Test
  public void shouldNotAutoRegisterAgentIfKeysDoNotMatch() throws Exception {
    String uuid = "uuid";
    when(goConfigService.hasAgent(uuid)).thenReturn(false);
    ServerConfig serverConfig =
        new ServerConfig("artifacts", new SecurityConfig(), 10, 20, "1", "");
    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, 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));
  }
コード例 #2
0
  @Test
  public void shouldAutoRegisterAgentWithHostnameFromAutoRegisterProperties() throws Exception {
    String uuid = "uuid";
    when(goConfigService.hasAgent(uuid)).thenReturn(false);
    ServerConfig serverConfig =
        new ServerConfig("artifacts", new SecurityConfig(), 10, 20, "1", "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,
        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")));
  }
コード例 #3
0
  @Test
  public void shouldRegisterWithProvidedAgentInformation() throws Exception {
    when(goConfigService.hasAgent("blahAgent-uuid")).thenReturn(false);
    ServerConfig serverConfig =
        new ServerConfig("artifacts", new SecurityConfig(), 10, 20, "1", null);
    when(goConfigService.serverConfig()).thenReturn(serverConfig);
    when(agentService.agentUsername("blahAgent-uuid", request.getRemoteAddr(), "blahAgent-host"))
        .thenReturn(new Username("some-agent-login-name"));

    ModelAndView modelAndView =
        controller.agentRequest(
            "blahAgent-host",
            "blahAgent-uuid",
            "blah-location",
            "34567",
            "osx",
            "",
            "",
            "",
            "",
            "",
            "",
            false,
            request);
    assertThat(modelAndView.getView().getContentType(), is("application/json"));

    verify(agentService)
        .requestRegistration(
            new Username("some-agent-login-name"),
            AgentRuntimeInfo.fromServer(
                new AgentConfig("blahAgent-uuid", "blahAgent-host", request.getRemoteAddr()),
                false,
                "blah-location",
                34567L,
                "osx",
                false));
  }