|
15 | 15 | from fastapi_sso.sso.facebook import FacebookSSO
|
16 | 16 | from fastapi_sso.sso.yandex import YandexSSO
|
17 | 17 |
|
18 |
| -sso_mapping: Dict[Type[SSOBase], Tuple[Dict[str, Any], OpenID]] = { |
19 |
| - TwitterSSO: ( |
| 18 | +sso_test_cases: Tuple[Type[SSOBase], Tuple[Dict[str, Any], OpenID]] = ( |
| 19 | + ( |
| 20 | + TwitterSSO, |
20 | 21 | {"data": {"id": "test", "username": "TestUser1234", "name": "Test User"}},
|
21 | 22 | OpenID(id="test", display_name="TestUser1234", first_name="Test", last_name="User", provider="twitter"),
|
22 | 23 | ),
|
23 |
| - SpotifySSO: ( |
| 24 | + ( |
| 25 | + SpotifySSO, |
24 | 26 | {"email": "test@example.com", "display_name": "testuser", "id": "test", "images": [{"url": "https://myimage"}]},
|
25 | 27 | OpenID(
|
26 | 28 | id="test", provider="spotify", display_name="testuser", email="test@example.com", picture="https://myimage"
|
27 | 29 | ),
|
28 | 30 | ),
|
29 |
| - NaverSSO: ({"properties": {"nickname": "test"}}, OpenID(display_name="test", provider="naver")), |
30 |
| - MicrosoftSSO: ( |
| 31 | + (NaverSSO, {"properties": {"nickname": "test"}}, OpenID(display_name="test", provider="naver")), |
| 32 | + ( |
| 33 | + MicrosoftSSO, |
31 | 34 | {"mail": "test@example.com", "displayName": "Test User", "id": "test", "givenName": "Test", "surname": "User"},
|
32 | 35 | OpenID(
|
33 | 36 | email="test@example.com",
|
|
38 | 41 | last_name="User",
|
39 | 42 | ),
|
40 | 43 | ),
|
41 |
| - LinkedInSSO: ( |
| 44 | + ( |
| 45 | + LinkedInSSO, |
42 | 46 | {
|
43 | 47 | "email": "test@example.com",
|
44 | 48 | "sub": "test",
|
|
55 | 59 | picture="https://myimage",
|
56 | 60 | ),
|
57 | 61 | ),
|
58 |
| - LineSSO: ( |
| 62 | + ( |
| 63 | + LineSSO, |
59 | 64 | {"email": "test@example.com", "name": "Test User", "sub": "test", "picture": "https://myimage"},
|
60 | 65 | OpenID(
|
61 | 66 | email="test@example.com", display_name="Test User", id="test", picture="https://myimage", provider="line"
|
62 | 67 | ),
|
63 | 68 | ),
|
64 |
| - KakaoSSO: ({"properties": {"nickname": "Test User"}}, OpenID(provider="kakao", display_name="Test User")), |
65 |
| - GitlabSSO: ( |
| 69 | + (KakaoSSO, {"properties": {"nickname": "Test User"}}, OpenID(provider="kakao", display_name="Test User")), |
| 70 | + ( |
| 71 | + # Gitlab Case 1: full name is empty |
| 72 | + GitlabSSO, |
66 | 73 | {"email": "test@example.com", "id": "test", "username": "test_user", "avatar_url": "https://myimage"},
|
67 | 74 | OpenID(
|
68 | 75 | email="test@example.com", id="test", display_name="test_user", picture="https://myimage", provider="gitlab"
|
69 | 76 | ),
|
70 | 77 | ),
|
71 |
| - GithubSSO: ( |
| 78 | + ( |
| 79 | + # Gitlab Case 2: full name contains only first name |
| 80 | + GitlabSSO, |
| 81 | + { |
| 82 | + "email": "test@example.com", |
| 83 | + "id": "test", |
| 84 | + "username": "test_user", |
| 85 | + "avatar_url": "https://myimage", |
| 86 | + "name": "Test", |
| 87 | + }, |
| 88 | + OpenID( |
| 89 | + email="test@example.com", |
| 90 | + id="test", |
| 91 | + display_name="test_user", |
| 92 | + picture="https://myimage", |
| 93 | + first_name="Test", |
| 94 | + last_name=None, |
| 95 | + provider="gitlab", |
| 96 | + ), |
| 97 | + ), |
| 98 | + ( |
| 99 | + # Gitlab Case 3: full name contains long last name |
| 100 | + GitlabSSO, |
| 101 | + { |
| 102 | + "email": "test@example.com", |
| 103 | + "id": "test", |
| 104 | + "username": "test_user", |
| 105 | + "avatar_url": "https://myimage", |
| 106 | + "name": "Test User Long Last Name", |
| 107 | + }, |
| 108 | + OpenID( |
| 109 | + email="test@example.com", |
| 110 | + id="test", |
| 111 | + display_name="test_user", |
| 112 | + picture="https://myimage", |
| 113 | + first_name="Test", |
| 114 | + last_name="User Long Last Name", |
| 115 | + provider="gitlab", |
| 116 | + ), |
| 117 | + ), |
| 118 | + ( |
| 119 | + # Gitlab Case 4: full name contains standard first and last names |
| 120 | + GitlabSSO, |
| 121 | + { |
| 122 | + "email": "test@example.com", |
| 123 | + "id": "test", |
| 124 | + "username": "test_user", |
| 125 | + "avatar_url": "https://myimage", |
| 126 | + "name": "Test User", |
| 127 | + }, |
| 128 | + OpenID( |
| 129 | + email="test@example.com", |
| 130 | + id="test", |
| 131 | + display_name="test_user", |
| 132 | + picture="https://myimage", |
| 133 | + first_name="Test", |
| 134 | + last_name="User", |
| 135 | + provider="gitlab", |
| 136 | + ), |
| 137 | + ), |
| 138 | + ( |
| 139 | + # Gitlab Case 5: full name contains invalid type or data |
| 140 | + GitlabSSO, |
| 141 | + { |
| 142 | + "email": "test@example.com", |
| 143 | + "id": "test", |
| 144 | + "username": "test_user", |
| 145 | + "avatar_url": "https://myimage", |
| 146 | + "name": {"invalid": 1}, |
| 147 | + }, |
| 148 | + OpenID( |
| 149 | + email="test@example.com", |
| 150 | + id="test", |
| 151 | + display_name="test_user", |
| 152 | + picture="https://myimage", |
| 153 | + first_name=None, |
| 154 | + last_name=None, |
| 155 | + provider="gitlab", |
| 156 | + ), |
| 157 | + ), |
| 158 | + ( |
| 159 | + GithubSSO, |
72 | 160 | {"email": "test@example.com", "id": "test", "login": "testuser", "avatar_url": "https://myimage"},
|
73 | 161 | OpenID(
|
74 | 162 | email="test@example.com", id="test", display_name="testuser", picture="https://myimage", provider="github"
|
75 | 163 | ),
|
76 | 164 | ),
|
77 |
| - FitbitSSO: ( |
| 165 | + ( |
| 166 | + FitbitSSO, |
78 | 167 | {"user": {"encodedId": "test", "fullName": "Test", "displayName": "Test User", "avatar": "https://myimage"}},
|
79 | 168 | OpenID(id="test", first_name="Test", display_name="Test User", provider="fitbit", picture="https://myimage"),
|
80 | 169 | ),
|
81 |
| - FacebookSSO: ( |
| 170 | + ( |
| 171 | + FacebookSSO, |
82 | 172 | {
|
83 | 173 | "email": "test@example.com",
|
84 | 174 | "first_name": "Test",
|
|
97 | 187 | picture="https://myimage",
|
98 | 188 | ),
|
99 | 189 | ),
|
100 |
| - YandexSSO: ( |
| 190 | + ( |
| 191 | + YandexSSO, |
101 | 192 | {
|
102 | 193 | "id": "test",
|
103 | 194 | "display_name": "test",
|
|
116 | 207 | picture="https://avatars.yandex.net/get-yapic/123456/islands-200",
|
117 | 208 | ),
|
118 | 209 | ),
|
119 |
| -} |
| 210 | +) |
120 | 211 |
|
121 | 212 |
|
122 |
| -@pytest.mark.parametrize( |
123 |
| - ("ProviderClass", "response", "openid"), [(key, value[0], value[1]) for key, value in sso_mapping.items()] |
124 |
| -) |
| 213 | +@pytest.mark.parametrize(("ProviderClass", "response", "openid"), sso_test_cases) |
125 | 214 | async def test_provider_openid_by_response(
|
126 | 215 | ProviderClass: Type[SSOBase], response: Dict[str, Any], openid: OpenID
|
127 | 216 | ) -> None:
|
|
0 commit comments