use of com.thoughtworks.go.server.newsecurity.models.UsernamePassword in project gocd by gocd.
the class InvalidateAuthenticationOnSecurityConfigChangeFilterTest method shouldContinueWithTheChainIfTheSecurityConfigHasNotChanged.
@Test
void shouldContinueWithTheChainIfTheSecurityConfigHasNotChanged() throws IOException, ServletException {
request = HttpRequestBuilder.GET("/").withRequestedSessionIdFromSession().build();
final AuthenticationToken<UsernamePassword> authenticationToken = setupAuthentication();
SessionUtils.setAuthenticationTokenAfterRecreatingSession(authenticationToken, request);
final HttpSession originalSession = request.getSession(false);
assertThat(SessionUtils.getAuthenticationToken(request).isAuthenticated(clock, systemEnvironment)).isTrue();
filter.doFilter(request, response, filterChain);
assertThat(request.getSession(false).getAttribute(SECURITY_CONFIG_LAST_CHANGE)).isEqualTo(clock.currentTimeMillis());
long timeBeforeConfigChange = clock.currentTimeMillis();
clock.addSeconds(1);
cruiseConfig.addEnvironment("Foo");
filter.onConfigChange(GoConfigMother.deepClone(cruiseConfig));
response.reset();
filter.doFilter(request, response, filterChain);
assertThat(SessionUtils.getAuthenticationToken(request).isAuthenticated(clock, systemEnvironment)).isTrue();
assertThat(request.getSession(false)).isSameAs(originalSession);
assertThat(request.getSession(false).getAttribute(SECURITY_CONFIG_LAST_CHANGE)).isEqualTo(timeBeforeConfigChange);
verifyNoInteractions(cacheService);
}
use of com.thoughtworks.go.server.newsecurity.models.UsernamePassword in project gocd by gocd.
the class DashBoardControllerTest method shouldResolveDashboardViewForStandby.
@Test
void shouldResolveDashboardViewForStandby() {
when(authToken.isValid()).thenReturn(true);
when(authToken.toUsernamePassword()).thenReturn(new UsernamePassword(USERNAME, PASSWORD));
when(addOnConfiguration.isServerInStandby()).thenReturn(true);
when(railsAssetsService.getAssetPath("application.css")).thenReturn("application.css");
when(railsAssetsService.getAssetPath("patterns/application.css")).thenReturn("patterns/application.css");
when(railsAssetsService.getAssetPath("application.js")).thenReturn("application.js");
when(railsAssetsService.getAssetPath("cruise.ico")).thenReturn("cruise.ico");
Map<String, String> expectedModelMap = new HashMap<>();
expectedModelMap.put("REPLACED_BY_GO:application.css", "application.css");
expectedModelMap.put("REPLACED_BY_GO:patterns/application.css", "patterns/application.css");
expectedModelMap.put("REPLACED_BY_GO:application.js", "application.js");
expectedModelMap.put("REPLACED_BY_GO:cruise.ico", "cruise.ico");
String template = "<html></html>";
when(viewResolver.resolveView("standby_dashboard", expectedModelMap)).thenReturn(template);
HttpServletRequest request = HttpRequestBuilder.GET("").withBasicAuth(USERNAME, PASSWORD).build();
String view = controller.dashboard(request, null);
assertThat(view).isEqualTo(template);
}
use of com.thoughtworks.go.server.newsecurity.models.UsernamePassword in project gocd by gocd.
the class DashBoardControllerTest method shouldProvideDashboardContentsForStandby.
@Test
void shouldProvideDashboardContentsForStandby() {
when(authToken.isValid()).thenReturn(true);
when(authToken.toUsernamePassword()).thenReturn(new UsernamePassword(USERNAME, PASSWORD));
when(authToken.forHttp()).thenReturn(CREDENTIALS);
HttpServletRequest request = HttpRequestBuilder.GET("").withBasicAuth(USERNAME, PASSWORD).build();
httpClientMock.onGet("https://localhost:8154/go/add-on/business-continuity/api/health-check").withHeader("Authorization", AUTHORIZATION_HEADER_VALUE).doReturnStatus(200);
httpClientMock.onGet("https://localhost:8154/go/add-on/business-continuity/api/latest_database_wal_location").withHeader("Authorization", AUTHORIZATION_HEADER_VALUE).doReturn(200, "/logs/location");
httpClientMock.onGet("https://localhost:8154/go/add-on/business-continuity/api/config_files_status").withHeader("Authorization", AUTHORIZATION_HEADER_VALUE).doReturn(200, "{\"configFilesUpdateInterval\":10,\"fileDetailsMap\":{\"CRUISE_CONFIG_XML\":{\"md5\":\"a\"}}}");
httpClientMock.onGet("https://localhost:8154/go/add-on/business-continuity/api/plugin_files_status").withHeader("Authorization", AUTHORIZATION_HEADER_VALUE).doReturn(200, "{\"bundled\":[{\"name\":\"yum.jar\",\"md5\":\"LAVBbwaDykricDnAP57klg\\u003d\\u003d\"}],\"external\":[{\"name\":\"external1.jar\",\"md5\":\"+yWDK4+tYQtfqyh3tmT95A\\u003d\\u003d\"},{\"name\":\"external2.jar\",\"md5\":\"DS/Oa0vv5URteXfzSU7mvQ\\u003d\\u003d\"}]}");
when(addOnConfiguration.isServerInStandby()).thenReturn(true);
MockHttpServletResponse response = new MockHttpServletResponse();
String dashboardData = controller.dashboardData(request, response);
MockHttpServletResponseAssert.assertThat(response).hasStatus(200);
JsonFluentAssert.assertThatJson(dashboardData).isEqualTo("{\n" + " \"setupStatus\": \"success\",\n" + " \"userName\": \"bob\",\n" + " \"standbyServerDetails\": {\n" + " \"primaryStatusCheckInterval\": 0,\n" + " \"pluginStatus\": \"\",\n" + " \"lastUpdateTime\": " + new GsonBuilder().setDateFormat("MMM d, YYYY HH:mm:ss").create().toJson(new Date(0)) + "\n" + " },\n" + " \"primaryServerDetails\": {\n" + " \"latestDatabaseWalLocation\": \"/logs/location\",\n" + " \"configFilesUpdateInterval\": 10,\n" + " \"lastConfigUpdateTime\": " + new GsonBuilder().setDateFormat("MMM d, YYYY HH:mm:ss").create().toJson(new Date(0)) + ",\n" + " \"CRUISE_CONFIG_XML\": {\n" + " \"md5\": \"a\"\n" + " },\n" + " \"pluginStatus\": \"external1.jar\\u003d+yWDK4+tYQtfqyh3tmT95A\\u003d\\u003d, external2.jar\\u003dDS/Oa0vv5URteXfzSU7mvQ\\u003d\\u003d\",\n" + " \"url\": \"https://localhost:8154\"\n" + " },\n" + " \"syncErrors\": []\n" + "}");
}
use of com.thoughtworks.go.server.newsecurity.models.UsernamePassword in project gocd by gocd.
the class AuthTokenTest method shouldGetTheTokenStringAfterStrippingWhitespace.
@Test
public void shouldGetTheTokenStringAfterStrippingWhitespace() throws IOException {
AuthToken authToken = new AuthToken(systemEnvironment);
FileUtils.writeStringToFile(tokenFile, "\n\t bl = ah \r\n \t", UTF_8);
Assertions.assertThat(authToken.toUsernamePassword()).isEqualTo(new UsernamePassword("bl", "ah"));
Assertions.assertThat(authToken.forHttp()).isEqualTo("bl:ah");
}
Aggregations