Skip to content

Commit

Permalink
Closes #238 OAuth tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bukajsytlos authored and Brutus5000 committed Jul 25, 2018
1 parent 306eb2f commit 1512147
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions src/inttest/java/com/faforever/api/login/LoginTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.faforever.api.login;

import com.faforever.api.AbstractIntegrationTest;
import org.jetbrains.annotations.NotNull;
import org.junit.Before;
import org.junit.Test;
import org.springframework.test.web.servlet.ResultActions;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;

import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

public class LoginTest extends AbstractIntegrationTest {
private MultiValueMap<String, String> params;

@Override
@Before
public void setUp() {
super.setUp();
params = new LinkedMultiValueMap<>();
params.add("grant_type", "password");
params.add("client_id", "test");
params.add("client_secret", "test");
params.add("username", "MODERATOR");
params.add("password", "MODERATOR");
}

@Test
public void retrieveModeratorToken() throws Exception {
performOAuthTokenRequest(params)
.andExpect(status().isOk())
.andExpect(jsonPath("$.access_token", is(notNullValue())));
}

@Test
public void wrongUserName() throws Exception {
params.set("username", "invalid_username");
performOAuthTokenRequest(params)
.andExpect(status().isBadRequest());
}

@Test
public void wrongPassword() throws Exception {
params.set("password", "invalid_password");
performOAuthTokenRequest(params)
.andExpect(status().isBadRequest());
}

@Test
public void invalidClientSecret() throws Exception {
params.set("client_secret", "invalid_client_secret");
performOAuthTokenRequest(params)
.andExpect(status().isUnauthorized());
}

@Test
public void invalidClientId() throws Exception {
params.set("client_id", "invalid_client_id");
performOAuthTokenRequest(params)
.andExpect(status().isUnauthorized());
}

@NotNull
private ResultActions performOAuthTokenRequest(MultiValueMap<String, String> params) throws Exception {
return mockMvc.perform(
post("/oauth/token")
.params(params));
}
}

0 comments on commit 1512147

Please sign in to comment.