List of usage examples for com.squareup.okhttp Response code
int code
To view the source code for com.squareup.okhttp Response code.
Click Source Link
From source file:keywhiz.service.resources.SecretsDeliveryResourceIntegrationTest.java
License:Apache License
@Test public void returnsEmptyJsonArrayWhenUserHasNoSecrets() throws Exception { Request get = new Request.Builder().get().url(testUrl("/secrets")).build(); Response response = noSecretsClient.newCall(get).execute(); assertThat(response.code()).isEqualTo(200); assertThat(response.body().string()).isEqualTo("[]"); }
From source file:keywhiz.service.resources.SessionLoginResourceIntegrationTest.java
License:Apache License
@Test public void respondsToLogin() throws Exception { Request post = new Request.Builder().post(RequestBody.create(MediaType.parse("text/plain"), "")) .url(testUrl("/admin/login")).build(); Response response = client.newCall(post).execute(); assertThat(response.code()).isNotEqualTo(404); }
From source file:keywhiz.service.resources.SessionLoginResourceIntegrationTest.java
License:Apache License
@Test public void setsValidCookieForValidCredentials() throws Exception { Request post = buildLoginPost(DbSeedCommand.defaultUser, DbSeedCommand.defaultPassword); Response response = client.newCall(post).execute(); assertThat(response.code()).isEqualTo(303); List<String> cookieNames = Lists.newArrayList(); String sessionCookie = null;/*ww w .j a v a 2s.co m*/ for (String cookieString : response.headers(HttpHeaders.SET_COOKIE)) { cookieString = cookieString.substring(0, cookieString.indexOf(";")); String cookieName = cookieString.substring(0, cookieString.indexOf("=")); cookieNames.add(cookieName); if (cookieName.equals("session")) { sessionCookie = cookieString; } } assertThat(cookieNames).containsOnly("session", "XSRF-TOKEN"); Pattern pattern = Pattern.compile("^session=(.+)$"); assertThat(sessionCookie).matches(pattern); }
From source file:keywhiz.service.resources.SessionLoginResourceIntegrationTest.java
License:Apache License
@Test public void invalidCredentialsAreUnauthorized() throws Exception { Request request = buildLoginPost("username", "badpassword"); Response response = client.newCall(request).execute(); assertThat(response.code()).isEqualTo(401); }
From source file:keywhiz.service.resources.SessionLoginResourceIntegrationTest.java
License:Apache License
@Test public void insufficientRolesAreUnauthorized() throws Exception { Request request = buildLoginPost("username", "password"); Response response = client.newCall(request).execute(); assertThat(response.code()).isEqualTo(401); }
From source file:keywhiz.service.resources.SessionLoginResourceIntegrationTest.java
License:Apache License
@Test public void noFormDataIsBadRequest() throws Exception { Request request = buildLoginPost(null, null); Response response = client.newCall(request).execute(); assertThat(response.code()).isEqualTo(400); }
From source file:keywhiz.service.resources.SessionLoginResourceIntegrationTest.java
License:Apache License
@Test public void missingUsernameIsBadRequest() throws Exception { Request request = buildLoginPost(null, "password"); Response response = client.newCall(request).execute(); assertThat(response.code()).isEqualTo(400); }
From source file:keywhiz.service.resources.SessionLoginResourceIntegrationTest.java
License:Apache License
@Test public void missingPasswordIsBadRequest() throws Exception { Request request = buildLoginPost("username", null); Response response = client.newCall(request).execute(); assertThat(response.code()).isEqualTo(400); }
From source file:keywhiz.service.resources.SessionLogoutResourceIntegrationTest.java
License:Apache License
@Test public void sendsExpiredCookie() throws Exception { Request request = new Request.Builder().post(RequestBody.create(MediaType.parse("text/plain"), "")) .url(testUrl("/admin/logout")).build(); Response response = client.newCall(request).execute(); assertThat(response.code()).isEqualTo(303); List<String> cookies = response.headers(HttpHeaders.SET_COOKIE); assertThat(cookies).hasSize(1);//from w ww . j av a2 s .c o m NewCookie cookie = NewCookie.valueOf(cookies.get(0)); assertThat(cookie.getName()).isEqualTo("session"); assertThat(cookie.getValue()).isEqualTo("expired"); assertThat(cookie.getVersion()).isEqualTo(1); assertThat(cookie.getPath()).isEqualTo("/admin"); assertThat(cookie.isSecure()).isTrue(); assertThat(cookie.isHttpOnly()).isTrue(); assertThat(cookie.getExpiry()).isEqualTo(new Date(0)); }
From source file:keywhiz.service.resources.SessionMeResourceIntegrationTest.java
License:Apache License
@Test public void getInformation() throws IOException { User validUser = User.named(DbSeedCommand.defaultUser); client.newCall(buildLoginPost(validUser.getName(), DbSeedCommand.defaultPassword)).execute(); Request get = new Request.Builder().get().url(testUrl("/admin/me/")).build(); Response response = client.newCall(get).execute(); assertThat(response.body().string()).isEqualTo(mapper.writeValueAsString(validUser)); assertThat(response.code()).isEqualTo(200); }