-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Auth module refactoring and unit tests extension (#261)
Signed-off-by: Oleg Kopysov <[email protected]>
- Loading branch information
Showing
7 changed files
with
83 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,10 +32,12 @@ public void testToMember() { | |
profile.setName("John"); | ||
profile.setEmail("[email protected]"); | ||
profile.setProvider("OAuth2"); | ||
profile.setNickname("Johnny"); | ||
LPVSMember member = profile.toMember(); | ||
|
||
assertEquals("John", member.getName()); | ||
assertEquals("[email protected]", member.getEmail()); | ||
assertEquals("OAuth2", member.getProvider()); | ||
assertEquals("Johnny", profile.getNickname()); | ||
} | ||
} |
40 changes: 0 additions & 40 deletions
40
src/test/java/com/lpvs/entity/auth/OAuthAttributesTest.java
This file was deleted.
Oops, something went wrong.
69 changes: 69 additions & 0 deletions
69
src/test/java/com/lpvs/entity/enums/OAuthAttributesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/** | ||
* Copyright (c) 2023, Samsung Electronics Co., Ltd. All rights reserved. | ||
* <p> | ||
* Use of this source code is governed by a MIT license that can be | ||
* found in the LICENSE file. | ||
*/ | ||
|
||
package com.lpvs.entity.enums; | ||
|
||
import com.lpvs.entity.auth.MemberProfile; | ||
import com.lpvs.entity.enums.OAuthAttributes; | ||
import org.junit.jupiter.api.Test; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class OAuthAttributesTest { | ||
|
||
@Test | ||
public void testExtractOAuthAttributes() { | ||
Map<String, Object> attributesSub = new HashMap<String, Object>() {{ | ||
put("name", "testName"); | ||
put("nickname", "testName"); | ||
put("email", "testEmail"); | ||
}}; | ||
|
||
Map<String, Object> attributesKakao = new HashMap<String, Object>() {{ | ||
put("email", "testEmail"); | ||
put("profile", attributesSub); | ||
}}; | ||
|
||
Map<String, Object> attributes = new HashMap<String, Object>() {{ | ||
put("name", "testName"); | ||
put("email", "testEmail"); | ||
put("login", "testEmail"); | ||
put("response", attributesSub); | ||
put("kakao_account", attributesKakao); | ||
}}; | ||
|
||
MemberProfile profileGoogle = OAuthAttributes.extract("google", attributes); | ||
assertEquals("testName", profileGoogle.getName()); | ||
assertEquals("testEmail", profileGoogle.getEmail()); | ||
|
||
MemberProfile profileNaver = OAuthAttributes.extract("naver", attributes); | ||
assertEquals("testName", profileNaver.getName()); | ||
assertEquals("testEmail", profileNaver.getEmail()); | ||
|
||
MemberProfile profileKakao = OAuthAttributes.extract("kakao", attributes); | ||
assertEquals("testName", profileKakao.getName()); | ||
assertEquals("testEmail", profileKakao.getEmail()); | ||
|
||
MemberProfile profileGithub = OAuthAttributes.extract("github", attributes); | ||
assertEquals("testName", profileGithub.getName()); | ||
assertEquals("testEmail", profileGithub.getEmail()); | ||
} | ||
|
||
@Test | ||
public void testExtractOAuthAttributesUnknownProvider() { | ||
Map<String, Object> attributes = new HashMap<String, Object>() {{ | ||
put("name", "testName"); | ||
put("email", "testEmail"); | ||
}};; | ||
assertThrows(IllegalArgumentException.class, () -> { | ||
OAuthAttributes.extract("unknown", attributes); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters