Skip to content

Commit

Permalink
Merge pull request #25 from alessandro-candon/feature/accept_method
Browse files Browse the repository at this point in the history
feat(method): Add get method on get user
  • Loading branch information
alessandro-candon authored May 30, 2024
2 parents b97e7bc + a1301aa commit 857fbfa
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public UserInfoController(UserService userService, JwtService jwtService) {
this.userService = userService;
}

@PostMapping("/idp/userinfo.openid")
@RequestMapping(value = "/idp/userinfo.openid", method = {RequestMethod.GET, RequestMethod.POST})
public JsonNode get(
@RequestHeader(value = HttpHeaders.AUTHORIZATION, required = false) String token)
throws JsonProcessingException {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* Decathlon Italy - Tacos Team(C) 2024 */
package com.alessandrocandon.fakeoauth2.controller;

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import org.junit.jupiter.api.Test;
Expand All @@ -20,7 +20,7 @@ class UserInfoControllerTest {
@Autowired private MockMvc mockMvc;

@Test
void testGetToken() throws Exception {
void testPostUserInfo() throws Exception {
mockMvc
.perform(
post("/idp/userinfo.openid")
Expand All @@ -31,4 +31,30 @@ void testGetToken() throws Exception {
+ " eyJraWQiOiJNQUlOIiwicGkuYXRtIjoiNSIsImFsZyI6IlJTMjU2IiwidHlwIjoiSldUIn0.eyJzY29wZSI6WyJvcGVuaWQiLCJwcm9maWxlIl0sImF1dGhvcml6YXRpb25fZGV0YWlscyI6W10sImNsaWVudF9pZCI6Im15Y2lkIiwiaXNzIjoiZXhhbXBsZS5vcmciLCJqdGkiOiIxMjMiLCJzdWIiOiJhbGVzc2FuZHJvLWNhbmRvbiIsInVpZCI6ImFsZXNzYW5kcm8tY2FuZG9uIiwib3JpZ2luIjoiY29ycG9yYXRlIiwiaWF0IjoxNjkyMDI1MDU5LCJ1dWlkIjoieHh4eHh4eC00N2EzLTM0NGYtYmJiNC14eHh4eHgiLCJ1c2VyX2tleV9pZCI6MH0.rrK6SHgWzlQFAS4WAP9jnSfzmvWveCXYsiiRllyURkxqwC08Dxjf7oSGY8bZvSlCjOqMc7eCZZE9R5atQBy3RYcpKAWS4kCXatJCAvnxjEtYLH0RyzoGFQrHkhtX-_sH-Zu-7FPogjcBl5Z0jiBQ46HOHPJn8TYwNnona68xabnaeDzGwCz2Fpf34UBdzIkAdDLVFMA09pP80FAT8962u2OyyDPYpldLagIHGlfLG9NtX8NGBgpUAkPkC0r6Y8KOBdK4x2C3cyBORg9BrisfdamhCO1qRqzGWfO6nK1N6gAK4jLxEnL72oMyqM2nOUa-EsQ6skASk2G5phCpjEavUw"))
.andExpect(status().isOk());
}

@Test
void testGetUserInfo() throws Exception {
mockMvc
.perform(
get("/idp/userinfo.openid")
.content("")
.header(
HttpHeaders.AUTHORIZATION,
"Bearer"
+ " eyJraWQiOiJNQUlOIiwicGkuYXRtIjoiNSIsImFsZyI6IlJTMjU2IiwidHlwIjoiSldUIn0.eyJzY29wZSI6WyJvcGVuaWQiLCJwcm9maWxlIl0sImF1dGhvcml6YXRpb25fZGV0YWlscyI6W10sImNsaWVudF9pZCI6Im15Y2lkIiwiaXNzIjoiZXhhbXBsZS5vcmciLCJqdGkiOiIxMjMiLCJzdWIiOiJhbGVzc2FuZHJvLWNhbmRvbiIsInVpZCI6ImFsZXNzYW5kcm8tY2FuZG9uIiwib3JpZ2luIjoiY29ycG9yYXRlIiwiaWF0IjoxNjkyMDI1MDU5LCJ1dWlkIjoieHh4eHh4eC00N2EzLTM0NGYtYmJiNC14eHh4eHgiLCJ1c2VyX2tleV9pZCI6MH0.rrK6SHgWzlQFAS4WAP9jnSfzmvWveCXYsiiRllyURkxqwC08Dxjf7oSGY8bZvSlCjOqMc7eCZZE9R5atQBy3RYcpKAWS4kCXatJCAvnxjEtYLH0RyzoGFQrHkhtX-_sH-Zu-7FPogjcBl5Z0jiBQ46HOHPJn8TYwNnona68xabnaeDzGwCz2Fpf34UBdzIkAdDLVFMA09pP80FAT8962u2OyyDPYpldLagIHGlfLG9NtX8NGBgpUAkPkC0r6Y8KOBdK4x2C3cyBORg9BrisfdamhCO1qRqzGWfO6nK1N6gAK4jLxEnL72oMyqM2nOUa-EsQ6skASk2G5phCpjEavUw"))
.andExpect(status().isOk());
}

@Test
void testDeleteUserInfoFail() throws Exception {
mockMvc
.perform(
delete("/idp/userinfo.openid")
.content("")
.header(
HttpHeaders.AUTHORIZATION,
"Bearer"
+ " eyJraWQiOiJNQUlOIiwicGkuYXRtIjoiNSIsImFsZyI6IlJTMjU2IiwidHlwIjoiSldUIn0.eyJzY29wZSI6WyJvcGVuaWQiLCJwcm9maWxlIl0sImF1dGhvcml6YXRpb25fZGV0YWlscyI6W10sImNsaWVudF9pZCI6Im15Y2lkIiwiaXNzIjoiZXhhbXBsZS5vcmciLCJqdGkiOiIxMjMiLCJzdWIiOiJhbGVzc2FuZHJvLWNhbmRvbiIsInVpZCI6ImFsZXNzYW5kcm8tY2FuZG9uIiwib3JpZ2luIjoiY29ycG9yYXRlIiwiaWF0IjoxNjkyMDI1MDU5LCJ1dWlkIjoieHh4eHh4eC00N2EzLTM0NGYtYmJiNC14eHh4eHgiLCJ1c2VyX2tleV9pZCI6MH0.rrK6SHgWzlQFAS4WAP9jnSfzmvWveCXYsiiRllyURkxqwC08Dxjf7oSGY8bZvSlCjOqMc7eCZZE9R5atQBy3RYcpKAWS4kCXatJCAvnxjEtYLH0RyzoGFQrHkhtX-_sH-Zu-7FPogjcBl5Z0jiBQ46HOHPJn8TYwNnona68xabnaeDzGwCz2Fpf34UBdzIkAdDLVFMA09pP80FAT8962u2OyyDPYpldLagIHGlfLG9NtX8NGBgpUAkPkC0r6Y8KOBdK4x2C3cyBORg9BrisfdamhCO1qRqzGWfO6nK1N6gAK4jLxEnL72oMyqM2nOUa-EsQ6skASk2G5phCpjEavUw"))
.andExpect(status().is4xxClientError());
}
}

0 comments on commit 857fbfa

Please sign in to comment.