-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
141ab88
commit 93648c9
Showing
8 changed files
with
225 additions
and
0 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
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.descope.types | ||
|
||
import com.descope.sdk.DescopeAuth | ||
|
||
/** | ||
* The [DescopeTenant] class represents a tenant in Descope. | ||
* | ||
* You can retrieve the tenants for a user after authentication by calling [DescopeAuth.tenants]. | ||
* | ||
* @property tenantId The unique identifier for the user in the project. | ||
* This is either an automatically generated value or a custom value that was set | ||
* when the tenant was created. | ||
* @property name The name of the tenant. | ||
* @property customAttributes A mapping of any custom attributes associated with this tenant. The custom attributes | ||
* are managed via the Descope console. | ||
*/ | ||
data class DescopeTenant( | ||
val tenantId: String, | ||
val name: String, | ||
val customAttributes: Map<String, Any>, | ||
) |
117 changes: 117 additions & 0 deletions
117
descopesdk/src/test/java/com/descope/internal/routes/AuthTest.kt
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,117 @@ | ||
package com.descope.internal.routes | ||
|
||
import com.descope.internal.http.TenantsResponse | ||
import com.descope.internal.http.UserResponse | ||
import com.descope.types.RevokeType | ||
import kotlinx.coroutines.test.runTest | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Assert.assertNotNull | ||
import org.junit.Assert.assertTrue | ||
import org.junit.Test | ||
|
||
class AuthTest { | ||
@Test | ||
fun me() = runTest { | ||
val client = MockClient() | ||
val auth = Auth(client) | ||
client.assert = { route: String, _: Map<String, Any?>, headers: Map<String, String>, _: Map<String, String?> -> | ||
assertEquals("auth/me", route) | ||
val authorizationHeader = headers["Authorization"] | ||
assertNotNull(authorizationHeader) | ||
assertTrue(authorizationHeader!!.contains("refreshJwt")) | ||
} | ||
client.response = UserResponse( | ||
userId = "userId", | ||
loginIds = listOf("loginId"), | ||
name = "name", | ||
picture = null, | ||
email = null, | ||
verifiedEmail = false, | ||
phone = null, | ||
verifiedPhone = false, | ||
createdTime = 0L, | ||
customAttributes = emptyMap(), | ||
givenName = null, | ||
middleName = null, | ||
familyName = null, | ||
) | ||
val response = auth.me("refreshJwt") | ||
assertEquals("name", response.name) | ||
assertEquals(1, client.calls) | ||
} | ||
|
||
@Test | ||
fun tenants() = runTest { | ||
val client = MockClient() | ||
val auth = Auth(client) | ||
client.assert = { route: String, body: Map<String, Any?>, headers: Map<String, String>, _: Map<String, String?> -> | ||
assertEquals("auth/me/tenants", route) | ||
val authorizationHeader = headers["Authorization"] | ||
assertNotNull(authorizationHeader) | ||
assertTrue(authorizationHeader!!.contains("refreshJwt")) | ||
assertEquals(true, body["dct"]) | ||
} | ||
client.response = TenantsResponse( | ||
tenants = listOf( | ||
TenantsResponse.Tenant("id1", "t1", emptyMap()), | ||
TenantsResponse.Tenant("id2", "t2", mapOf("a" to "b", "c" to "d")) | ||
), | ||
) | ||
val response = auth.tenants(true, emptyList(), "refreshJwt") | ||
assertEquals(2, response.size) | ||
assertEquals("id1", response[0].tenantId) | ||
assertEquals("t1", response[0].name) | ||
assertEquals("id2", response[1].tenantId) | ||
assertEquals("t2", response[1].name) | ||
assertEquals(2, response[1].customAttributes.size) | ||
assertEquals(1, client.calls) | ||
} | ||
|
||
@Test | ||
fun refreshSession() = runTest { | ||
val client = MockClient() | ||
val auth = Auth(client) | ||
client.assert = { route: String, _: Map<String, Any?>, headers: Map<String, String>, _: Map<String, String?> -> | ||
assertEquals("auth/refresh", route) | ||
val authorizationHeader = headers["Authorization"] | ||
assertNotNull(authorizationHeader) | ||
assertTrue(authorizationHeader!!.contains("refreshJwt")) | ||
} | ||
client.response = mockJwtResponse | ||
val response = auth.refreshSession("refreshJwt") | ||
assertEquals(jwt, response.sessionToken.jwt) | ||
assertEquals(jwt, response.refreshToken!!.jwt) | ||
assertEquals(1, client.calls) | ||
} | ||
|
||
@Test | ||
fun revokeSession_current() = runTest { | ||
val client = MockClient() | ||
val auth = Auth(client) | ||
client.assert = { route: String, _: Map<String, Any?>, headers: Map<String, String>, _: Map<String, String?> -> | ||
assertEquals("auth/logout", route) | ||
val authorizationHeader = headers["Authorization"] | ||
assertNotNull(authorizationHeader) | ||
assertTrue(authorizationHeader!!.contains("refreshJwt")) | ||
} | ||
client.response = Unit | ||
auth.revokeSessions(RevokeType.CurrentSession, "refreshJwt") | ||
assertEquals(1, client.calls) | ||
} | ||
|
||
@Test | ||
fun revokeSession_all() = runTest { | ||
val client = MockClient() | ||
val auth = Auth(client) | ||
client.assert = { route: String, _: Map<String, Any?>, headers: Map<String, String>, _: Map<String, String?> -> | ||
assertEquals("auth/logoutall", route) | ||
val authorizationHeader = headers["Authorization"] | ||
assertNotNull(authorizationHeader) | ||
assertTrue(authorizationHeader!!.contains("refreshJwt")) | ||
} | ||
client.response = Unit | ||
auth.revokeSessions(RevokeType.AllSessions, "refreshJwt") | ||
assertEquals(1, client.calls) | ||
} | ||
|
||
} |
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