Skip to content

Commit

Permalink
#44 front end JavaScript library with key obfuscated - review
Browse files Browse the repository at this point in the history
  • Loading branch information
drnow4u committed Apr 5, 2022
1 parent 532b3f5 commit b57c98e
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
1 change: 1 addition & 0 deletions secondkey.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this is test secret
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

@Configuration
Expand All @@ -12,6 +11,8 @@ public class TokenCallbackSecurityConfiguration extends WebSecurityConfigurerAda

@Override
protected void configure(HttpSecurity http) throws Exception {
http.requestMatcher(r -> r.getRequestURL().toString().contains("canaries")).csrf().disable();
http.requestMatcher(r ->
r.getRequestURL().toString().contains("canaries") || r.getRequestURL().toString().contains("token"))
.csrf().disable();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package org.owasp.wrongsecrets.oauth;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;

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;

@AutoConfigureMockMvc
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class TokenControllerTest {

@Autowired
MockMvc mvc;

@Test
void shouldGetToken() throws Exception {
// When
var response = mvc.perform(post("/token")
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.content("grant_type=client_credentials&client_id=WRONGSECRET_CLIENT_ID&client_secret=this is test secret"));

// Then
response.andExpect(status().isOk())
.andExpect(jsonPath("$.access_token").exists())
.andExpect(jsonPath("$.token_type").value("bearer"))
.andExpect(jsonPath("$.expires_in").value(54321))
.andExpect(jsonPath("$.scope").value("user_info"));
}

@Test
void shouldNotGetToken() throws Exception {
// When
var response = mvc.perform(post("/token")
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.content("grant_type=client_credentials&client_id=WRONGSECRET_CLIENT_ID&client_secret=this wrong secret"));

// Then
response.andExpect(status().isUnauthorized());
}

}
1 change: 1 addition & 0 deletions src/test/resources/config/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ asciidoctor.enabled=true
hints_enabled=true
reason_enabled=true
azure.keyvault.enabled=false
challengedockermtpath=./

0 comments on commit b57c98e

Please sign in to comment.