Skip to content

Commit de21fa8

Browse files
authored
Merge pull request #73 from passageidentity/PSG-4613
PSG-4614
2 parents b9d43b2 + 1793760 commit de21fa8

File tree

8 files changed

+163
-108
lines changed

8 files changed

+163
-108
lines changed

.github/workflows/integration-tests.yml

+11-16
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
name: Integration tests
2+
23
on:
34
pull_request:
45
push:
56
branches: [main]
7+
68
jobs:
79
test:
810
runs-on: ubuntu-latest
911
strategy:
1012
matrix:
11-
api-level: [33] # TODO: add more api levels to test
13+
api-level: [33] # TODO: add more API levels to test
14+
1215
env:
1316
MAILOSAUR_API_KEY: ${{ secrets.MAILOSAUR_API_KEY }}
1417
OTP_TEST_USER_AUTH_TOKEN: ${{ secrets.OTP_TEST_USER_AUTH_TOKEN }}
1518
APP_API_KEY: ${{ secrets.APP_API_KEY }}
19+
1620
steps:
17-
- name: checkout
21+
- name: Checkout
1822
uses: actions/checkout@v4
1923

2024
- name: Setup JDK 17
@@ -41,23 +45,14 @@ jobs:
4145
~/.android/adb*
4246
key: avd-${{ matrix.api-level }}
4347

44-
- name: create AVD and generate snapshot for caching
45-
if: steps.avd-cache.outputs.cache-hit != 'true'
48+
- name: Create AVD and run tests
4649
uses: reactivecircus/android-emulator-runner@v2
4750
with:
4851
api-level: ${{ matrix.api-level }}
49-
force-avd-creation: false
52+
force-avd-creation: true
53+
wipe-data: true
5054
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
51-
disable-animations: false
52-
arch: x86_64
53-
script: echo "Generated AVD snapshot for caching."
54-
55-
- name: run tests
56-
uses: reactivecircus/android-emulator-runner@v2
57-
with:
58-
api-level: ${{ matrix.api-level }}
59-
force-avd-creation: false
60-
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
6155
disable-animations: true
6256
arch: x86_64
63-
script: ./gradlew connectedDebugAndroidTest
57+
script: |
58+
./gradlew clean connectedDebugAndroidTest

passage/src/androidTest/java/id/passage/android/PassageHostedTests.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ internal class PassageHostedTests {
6060
val expectedState = "state="
6161
val expectedCodeChallenge = "code_challenge="
6262

63-
passage.hosted.hostedAuthStart()
63+
passage.hosted.start()
6464

6565
intended(
6666
allOf(
@@ -86,7 +86,7 @@ internal class PassageHostedTests {
8686
runTest {
8787
try {
8888
val invalidAuthCode = "INVALID_AUTH_CODE"
89-
passage.hosted.hostedAuthFinish(invalidAuthCode, "")
89+
passage.hosted.finish(invalidAuthCode, "")
9090
fail("Test should throw FinishOIDCAuthenticationInvalidRequestException")
9191
} catch (e: Exception) {
9292
assertThat(e is HostedAuthorizationError)

passage/src/androidTest/java/id/passage/android/PassageSocialTests.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ internal class PassageSocialTests {
6464
val expectedState = "state="
6565
val expectedCodeChallenge = "code_challenge="
6666

67-
passage.social.authorizeWith(SocialConnection.github)
67+
passage.social.authorize(SocialConnection.github)
6868

6969
intended(
7070
allOf(

passage/src/androidTest/java/id/passage/android/TokenStoreTests.kt

+59-1
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ import id.passage.android.IntegrationTestConfig.Companion.API_BASE_URL
88
import id.passage.android.IntegrationTestConfig.Companion.APP_ID_OTP
99
import id.passage.android.IntegrationTestConfig.Companion.EXISTING_USER_EMAIL_OTP
1010
import id.passage.android.IntegrationTestConfig.Companion.WAIT_TIME_MILLISECONDS
11+
import id.passage.android.exceptions.PassageTokenException
1112
import id.passage.android.exceptions.PassageUserUnauthorizedException
1213
import id.passage.android.exceptions.UserInfoUnauthorizedException
14+
import id.passage.android.model.AuthResult
15+
import junit.framework.TestCase.assertNotNull
1316
import junit.framework.TestCase.fail
1417
import kotlinx.coroutines.delay
1518
import kotlinx.coroutines.runBlocking
@@ -24,6 +27,7 @@ import org.junit.runner.RunWith
2427
@RunWith(AndroidJUnit4::class)
2528
internal class TokenStoreTests {
2629
private lateinit var passage: Passage
30+
private var refreshToken = ""
2731

2832
@Before
2933
fun setup(): Unit =
@@ -38,7 +42,8 @@ internal class TokenStoreTests {
3842
val otpId = passage.oneTimePasscode.login(EXISTING_USER_EMAIL_OTP).otpId
3943
delay(WAIT_TIME_MILLISECONDS)
4044
val otp = MailosaurAPIClient.getMostRecentOneTimePasscode()
41-
passage.oneTimePasscode.activate(otp, otpId)
45+
val authResult = passage.oneTimePasscode.activate(otp, otpId)
46+
refreshToken = authResult.authToken
4247
}
4348

4449
@After
@@ -111,4 +116,57 @@ internal class TokenStoreTests {
111116
assertThat(e is PassageUserUnauthorizedException)
112117
}
113118
}
119+
120+
@Test
121+
fun getValidAuthTokenWithValidToken() =
122+
runTest {
123+
val result = passage.tokenStore.getValidAuthToken()
124+
assertNotNull(result)
125+
}
126+
127+
@Test
128+
fun getValidAuthTokenWithInvalidToken() =
129+
runTest {
130+
try {
131+
passage.tokenStore.setTokens(AuthResult("invalid", ""))
132+
passage.tokenStore.getValidAuthToken()
133+
fail("Test should throw PassageTokenException")
134+
} catch (e: Exception) {
135+
assertThat(e is PassageTokenException)
136+
}
137+
}
138+
139+
@Test
140+
fun isAuthTokenValidWithValidToken() {
141+
val validToken = IntegrationTestConfig.AUTH_TOEKN
142+
val result = passage.tokenStore.isAuthTokenValid(validToken)
143+
assertThat(result).isTrue()
144+
}
145+
146+
@Test
147+
fun isAuthTokenValidWithInvalidToken() {
148+
val invalidToken = "invalidAuthToken"
149+
val result = passage.tokenStore.isAuthTokenValid(invalidToken)
150+
assertThat(result).isFalse()
151+
}
152+
153+
@Test
154+
fun revokedWithValidToken() =
155+
runTest {
156+
val validRefreshToken = refreshToken
157+
passage.tokenStore.revokeRefreshToken(validRefreshToken)
158+
// should not throw any error
159+
}
160+
161+
@Test
162+
fun refreshWithInvalidToken(): Unit =
163+
runBlocking {
164+
try {
165+
val invalidRefreshToken = "invalid"
166+
val authResult = passage.tokenStore.refreshAuthToken(invalidRefreshToken)
167+
fail("Test should throw PassageTokenException")
168+
} catch (e: Exception) {
169+
assertThat(e is PassageTokenException)
170+
}
171+
}
114172
}

passage/src/main/java/id/passage/android/PassageHosted.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class PassageHosted(
1515
* If your Passage app is Hosted, use this method to register and log in your user.
1616
* This method will open up a Passage login experience on a Chrome tab.
1717
*/
18-
fun hostedAuthStart() {
18+
fun start() {
1919
HostedUtils.openChromeTab(
2020
activity,
2121
)
@@ -31,7 +31,7 @@ class PassageHosted(
3131
* @throws HostedAuthorizationError
3232
*/
3333

34-
suspend fun hostedAuthFinish(
34+
suspend fun finish(
3535
code: String,
3636
state: String,
3737
): Pair<AuthResult, String> {

passage/src/main/java/id/passage/android/PassageSocial.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class PassageSocial(
1919
* Authorizes user via a supported third-party social provider.
2020
* @param connection The Social connection to use for authorization
2121
*/
22-
fun authorizeWith(connection: SocialConnection) {
22+
fun authorize(connection: SocialConnection) {
2323
SocialUtils.openChromeTab(
2424
connection,
2525
Passage.authOrigin,

passage/src/main/java/id/passage/android/PassageToken.kt

-77
This file was deleted.

0 commit comments

Comments
 (0)