コード例 #1
0
ファイル: CommandLineTest.java プロジェクト: qiaoliang/GoCD
 @Test
 public void shouldLogPasswordsOnTheLogAsStars() {
   LogFixture logFixture = LogFixture.startListening();
   LogFixture.enableDebug();
   CommandLine line =
       CommandLine.createCommandLine("notexist").withArg(new PasswordArgument("secret"));
   try {
     line.runOrBomb(null);
   } catch (Exception e) {
     // ignored
   }
   assertThat(ArrayUtil.join(logFixture.getMessages()), containsString("notexist ******"));
   logFixture.stopListening();
 }
コード例 #2
0
ファイル: CommandLineTest.java プロジェクト: qiaoliang/GoCD
 @Test
 @RunIf(
     value = EnhancedOSChecker.class,
     arguments = {DO_NOT_RUN_ON, OSChecker.WINDOWS})
 public void shouldNotLogPasswordsFromStream() {
   LogFixture logFixture = LogFixture.startListening();
   CommandLine line =
       CommandLine.createCommandLine("/bin/echo")
           .withArg("=>")
           .withArg(new PasswordArgument("secret"));
   line.runOrBomb(null);
   System.out.println(ArrayUtil.join(logFixture.getMessages()));
   assertThat(ArrayUtil.join(logFixture.getMessages()), not(containsString("secret")));
   assertThat(ArrayUtil.join(logFixture.getMessages()), containsString("=> ******"));
   logFixture.stopListening();
 }
コード例 #3
0
 @Test
 public void shouldThrowExceptionWhenAgentWithNoCookieTriesToUpdateStatus() throws Exception {
   AgentRuntimeInfo runtimeInfo =
       new AgentRuntimeInfo(
           agentIdentifier, AgentRuntimeStatus.Idle, currentWorkingDirectory(), null, null);
   try {
     agentService.updateRuntimeInfo(runtimeInfo);
     fail("should throw exception when no cookie is set");
   } catch (Exception e) {
     assertThat(e, instanceOf(AgentNoCookieSetException.class));
     assertThat(
         e.getMessage(),
         is(format("Agent [%s] has no cookie set", runtimeInfo.agentInfoDebugString())));
     assertThat(
         Arrays.asList(logFixture.getMessages()),
         hasItem(format("Agent [%s] has no cookie set", runtimeInfo.agentInfoDebugString())));
   }
 }
コード例 #4
0
 @Test
 public void shouldThrowExceptionWhenADuplicateAgentTriesToUpdateStatus() throws Exception {
   AgentRuntimeInfo runtimeInfo =
       new AgentRuntimeInfo(
           agentIdentifier, AgentRuntimeStatus.Idle, currentWorkingDirectory(), null, null);
   runtimeInfo.setCookie("invalid_cookie");
   AgentInstance original =
       AgentInstance.createFromLiveAgent(
           new AgentRuntimeInfo(
               agentIdentifier, AgentRuntimeStatus.Idle, currentWorkingDirectory(), null, null),
           new SystemEnvironment());
   try {
     when(agentService.findAgentAndRefreshStatus(runtimeInfo.getUUId())).thenReturn(original);
     agentService.updateRuntimeInfo(runtimeInfo);
     fail("should throw exception when cookie mismatched");
   } catch (Exception e) {
     assertThat(
         e.getMessage(),
         is(format("Agent [%s] has invalid cookie", runtimeInfo.agentInfoDebugString())));
     assertThat(
         Arrays.asList(logFixture.getMessages()),
         hasItem(
             format(
                 "Found agent [%s] with duplicate uuid. Please check the agent installation.",
                 runtimeInfo.agentInfoDebugString())));
     verify(serverHealthService)
         .update(
             ServerHealthState.warning(
                 format(
                     "[%s] has duplicate unique identifier which conflicts with [%s]",
                     runtimeInfo.agentInfoForDisplay(), original.agentInfoForDisplay()),
                 "Please check the agent installation. Click <a href='http://www.go.cd/documentation/user/current/faq/agent_guid_issue.html' target='_blank'>here</a> for more info.",
                 HealthStateType.duplicateAgent(
                     HealthStateScope.forAgent(runtimeInfo.getCookie())),
                 Timeout.THIRTY_SECONDS));
   }
   verify(agentInstances).findAgentAndRefreshStatus(runtimeInfo.getUUId());
   verifyNoMoreInteractions(agentInstances);
 }
コード例 #5
0
 @Before
 public void setUp() {
   agentInstances = mock(AgentInstances.class);
   config = new AgentConfig("uuid", "host", "192.168.1.1");
   when(agentInstances.findAgentAndRefreshStatus("uuid"))
       .thenReturn(AgentInstance.createFromConfig(config, new SystemEnvironment()));
   agentDao = mock(AgentDao.class);
   uuidGenerator = mock(UuidGenerator.class);
   agentService =
       new AgentService(
           mock(AgentConfigService.class),
           new SystemEnvironment(),
           agentInstances,
           mock(EnvironmentConfigService.class),
           mock(GoConfigService.class),
           mock(SecurityService.class),
           agentDao,
           uuidGenerator,
           serverHealthService = mock(ServerHealthService.class));
   logFixture = LogFixture.startListening();
   agentIdentifier = config.getAgentIdentifier();
   when(agentDao.cookieFor(agentIdentifier)).thenReturn("cookie");
 }