File tree Expand file tree Collapse file tree 3 files changed +27
-18
lines changed
main/java/dev/findfirst/users
test/java/dev/findfirst/users/controller Expand file tree Collapse file tree 3 files changed +27
-18
lines changed Original file line number Diff line number Diff line change 3737
3838import lombok .RequiredArgsConstructor ;
3939import lombok .extern .slf4j .Slf4j ;
40+ import org .springframework .beans .factory .annotation .Autowired ;
4041import org .springframework .beans .factory .annotation .Value ;
4142import org .springframework .core .io .FileSystemResource ;
4243import org .springframework .core .io .Resource ;
@@ -63,8 +64,12 @@ public class UserController {
6364
6465 private final RefreshTokenService refreshTokenService ;
6566
66- private final Oauth2SourceService oauth2SourceService ;
67+ private Oauth2SourceService oauth2SourceService ;
6768
69+ @ Autowired (required = false )
70+ public void setOauth2SourceService (Oauth2SourceService oauth2SourceService ) {
71+ this .oauth2SourceService = oauth2SourceService ;
72+ }
6873
6974 @ Value ("${findfirst.app.frontend-url}" )
7075 private String frontendUrl ;
@@ -87,6 +92,10 @@ public ResponseEntity<User> userInfo() throws NoUserFoundException {
8792
8893 @ GetMapping ("/oauth2Providers" )
8994 public ResponseEntity <List <Oauth2Source >> oauth2Providers () {
95+ if (oauth2SourceService == null ) {
96+ // return a blank list.
97+ return ResponseEntity .ok (List .of ());
98+ }
9099 return ResponseEntity .ok (oauth2SourceService .oauth2Sources ());
91100 }
92101
Original file line number Diff line number Diff line change @@ -28,18 +28,20 @@ public class Oauth2SourceService {
2828
2929 @ PostConstruct
3030 void init () {
31- oauth2Providers .iterator ().forEachRemaining (provider -> {
32- var tknUri = provider .getProviderDetails ().getTokenUri ();
33- log .debug ("Token URI {}" , tknUri );
34- // skip http(s)://
35- if (!tknUri .contains ("https://" )) {
36- log .debug ("provider without https {}" , tknUri );
37- // do we really want to trust anything that isn't https?
38- return ;
39- }
40- oauth2Sources .add (new Oauth2Source (provider .getClientName (), getFaviconURI (provider ),
41- "oauth2/authorization/" + provider .getRegistrationId ()));
42- });
31+ if (oauth2Providers != null ) {
32+ oauth2Providers .iterator ().forEachRemaining (provider -> {
33+ var tknUri = provider .getProviderDetails ().getTokenUri ();
34+ log .debug ("Token URI {}" , tknUri );
35+ // skip http(s)://
36+ if (!tknUri .contains ("https://" )) {
37+ log .debug ("provider without https {}" , tknUri );
38+ // do we really want to trust anything that isn't https?
39+ return ;
40+ }
41+ oauth2Sources .add (new Oauth2Source (provider .getClientName (), getFaviconURI (provider ),
42+ "oauth2/authorization/" + provider .getRegistrationId ()));
43+ });
44+ }
4345 }
4446
4547 public List <Oauth2Source > oauth2Sources () {
Original file line number Diff line number Diff line change 11package dev .findfirst .users .controller ;
22
33import static dev .findfirst .utilities .HttpUtility .getHttpEntity ;
4- import static org .junit .jupiter .api .Assertions .assertArrayEquals ;
54import static org .junit .jupiter .api .Assertions .assertEquals ;
65import static org .junit .jupiter .api .Assertions .assertNotNull ;
76import static org .junit .jupiter .api .Assertions .assertTrue ;
@@ -247,9 +246,8 @@ void testRemoveUserPhoto_Success() throws Exception {
247246 @ Test
248247 void getAllProivders () {
249248 var response = restTemplate .getForEntity ("/user/oauth2Providers" , Oauth2Source [].class );
250-
251- assertArrayEquals (new Oauth2Source [] {new Oauth2Source ("GitHub" ,
252- "https://github.com/favicon.ico" , "oauth2/authorization/github" )}, response .getBody ());
253-
249+ var sources = response .getBody ();
250+ assertTrue (sources .length == 1 );
251+ assertEquals ("GitHub" , sources [0 ].provider (), "Github should be the provider." );
254252 }
255253}
You can’t perform that action at this time.
0 commit comments