Skip to content

Renaming getAuthToken to getToken. #1026

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public interface FirebaseInstallationsApi {
int DO_NOT_FORCE_REFRESH = 0;
/**
* AuthToken is forcefully refreshed on calling the {@link
* FirebaseInstallationsApi#getAuthToken(int)}.
* FirebaseInstallationsApi#getToken(int)}.
*/
int FORCE_REFRESH = 1;

Expand All @@ -50,7 +50,7 @@ public interface FirebaseInstallationsApi {
Task<String> getId();

/** Async function that returns a auth token(public key) of this Firebase app installation. */
Task<InstallationTokenResult> getAuthToken(@AuthTokenOption int authTokenOption);
Task<InstallationTokenResult> getToken(@AuthTokenOption int authTokenOption);

/**
* Async function that deletes this Firebase app installation from Firebase backend. This call
Expand Down
2 changes: 1 addition & 1 deletion firebase-installations/api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package com.google.firebase.installations {

public class FirebaseInstallations {
method @NonNull public Task<Void> delete();
method @NonNull public Task<InstallationTokenResult> getAuthToken(int);
method @NonNull public Task<String> getId();
method @NonNull public static com.google.firebase.installations.FirebaseInstallations getInstance();
method @NonNull public static com.google.firebase.installations.FirebaseInstallations getInstance(@NonNull FirebaseApp);
method @NonNull public Task<InstallationTokenResult> getToken(int);
}

public class FirebaseInstallationsException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ public void testGetAuthToken_fidDoesNotExist_successful() throws Exception {
when(mockUtils.isAuthTokenExpired(REGISTERED_INSTALLATION_ENTRY)).thenReturn(/*isValid*/ false);
FirebaseInstallations firebaseInstallations = getFirebaseInstallations();

Tasks.await(firebaseInstallations.getAuthToken(FirebaseInstallationsApi.DO_NOT_FORCE_REFRESH));
Tasks.await(firebaseInstallations.getToken(FirebaseInstallationsApi.DO_NOT_FORCE_REFRESH));

PersistedInstallationEntry entryValue =
persistedInstallation.readPersistedInstallationEntryValue();
Expand All @@ -510,8 +510,7 @@ public void testGetAuthToken_PersistedInstallationError_failure() throws Excepti

// Expect exception
try {
Tasks.await(
firebaseInstallations.getAuthToken(FirebaseInstallationsApi.DO_NOT_FORCE_REFRESH));
Tasks.await(firebaseInstallations.getToken(FirebaseInstallationsApi.DO_NOT_FORCE_REFRESH));
fail("Could not update local storage.");
} catch (ExecutionException expected) {
assertWithMessage("Exception class doesn't match")
Expand Down Expand Up @@ -540,8 +539,7 @@ public void testGetAuthToken_fidExists_successful() throws Exception {
mockIidStore);

InstallationTokenResult installationTokenResult =
Tasks.await(
firebaseInstallations.getAuthToken(FirebaseInstallationsApi.DO_NOT_FORCE_REFRESH));
Tasks.await(firebaseInstallations.getToken(FirebaseInstallationsApi.DO_NOT_FORCE_REFRESH));

assertWithMessage("Persisted Auth Token doesn't match")
.that(installationTokenResult.getToken())
Expand All @@ -551,16 +549,15 @@ public void testGetAuthToken_fidExists_successful() throws Exception {
}

@Test
public void testGetAuthToken_expiredAuthToken_fetchedNewTokenFromFIS() throws Exception {
public void testGetToken_expiredAuthToken_fetchedNewTokenFromFIS() throws Exception {
persistedInstallation.insertOrUpdatePersistedInstallationEntry(EXPIRED_AUTH_TOKEN_ENTRY);
when(mockUtils.isAuthTokenExpired(EXPIRED_AUTH_TOKEN_ENTRY)).thenReturn(/*isExpired*/ true);
when(mockUtils.isAuthTokenExpired(UPDATED_AUTH_TOKEN_ENTRY)).thenReturn(/*isValid*/ false);

FirebaseInstallations firebaseInstallations = getFirebaseInstallations();

InstallationTokenResult installationTokenResult =
Tasks.await(
firebaseInstallations.getAuthToken(FirebaseInstallationsApi.DO_NOT_FORCE_REFRESH));
Tasks.await(firebaseInstallations.getToken(FirebaseInstallationsApi.DO_NOT_FORCE_REFRESH));

assertWithMessage("Persisted Auth Token doesn't match")
.that(installationTokenResult.getToken())
Expand All @@ -570,17 +567,16 @@ public void testGetAuthToken_expiredAuthToken_fetchedNewTokenFromFIS() throws Ex
}

@Test
public void testGetAuthToken_unregisteredFid_fetchedNewTokenFromFIS() throws Exception {
// Update local storage with a unregistered installation entry to validate that getAuthToken
public void testGetToken_unregisteredFid_fetchedNewTokenFromFIS() throws Exception {
// Update local storage with a unregistered installation entry to validate that getToken
// calls getId to ensure FID registration and returns a valid auth token.
persistedInstallation.insertOrUpdatePersistedInstallationEntry(UNREGISTERED_INSTALLATION_ENTRY);
when(mockUtils.isAuthTokenExpired(REGISTERED_INSTALLATION_ENTRY)).thenReturn(/*isValid*/ false);

FirebaseInstallations firebaseInstallations = getFirebaseInstallations();

InstallationTokenResult installationTokenResult =
Tasks.await(
firebaseInstallations.getAuthToken(FirebaseInstallationsApi.DO_NOT_FORCE_REFRESH));
Tasks.await(firebaseInstallations.getToken(FirebaseInstallationsApi.DO_NOT_FORCE_REFRESH));

assertWithMessage("Persisted Auth Token doesn't match")
.that(installationTokenResult.getToken())
Expand All @@ -590,7 +586,7 @@ public void testGetAuthToken_unregisteredFid_fetchedNewTokenFromFIS() throws Exc
}

@Test
public void testGetAuthToken_fidError_persistedInstallationCleared() throws Exception {
public void testGetToken_fidError_persistedInstallationCleared() throws Exception {
// Update local storage with an expired installation entry to ensure that generate auth token
// is called.
persistedInstallation.insertOrUpdatePersistedInstallationEntry(EXPIRED_AUTH_TOKEN_ENTRY);
Expand All @@ -606,8 +602,8 @@ public void testGetAuthToken_fidError_persistedInstallationCleared() throws Exce

// Expect exception
try {
Tasks.await(firebaseInstallations.getAuthToken(FirebaseInstallationsApi.FORCE_REFRESH));
fail("getAuthToken() failed due to Server Error.");
Tasks.await(firebaseInstallations.getToken(FirebaseInstallationsApi.FORCE_REFRESH));
fail("getToken() failed due to Server Error.");
} catch (ExecutionException expected) {
assertWithMessage("Exception class doesn't match")
.that(expected)
Expand All @@ -626,7 +622,7 @@ public void testGetAuthToken_fidError_persistedInstallationCleared() throws Exce
}

@Test
public void testGetAuthToken_serverError_failure() throws Exception {
public void testGetToken_serverError_failure() throws Exception {
when(mockPersistedInstallation.readPersistedInstallationEntryValue())
.thenReturn(REGISTERED_INSTALLATION_ENTRY);
when(backendClientReturnsError.generateAuthToken(
Expand All @@ -645,8 +641,8 @@ public void testGetAuthToken_serverError_failure() throws Exception {

// Expect exception
try {
Tasks.await(firebaseInstallations.getAuthToken(FirebaseInstallationsApi.FORCE_REFRESH));
fail("getAuthToken() failed due to Server Error.");
Tasks.await(firebaseInstallations.getToken(FirebaseInstallationsApi.FORCE_REFRESH));
fail("getToken() failed due to Server Error.");
} catch (ExecutionException expected) {
assertWithMessage("Exception class doesn't match")
.that(expected)
Expand All @@ -659,8 +655,7 @@ public void testGetAuthToken_serverError_failure() throws Exception {
}

@Test
public void testGetAuthToken_multipleCallsDoNotForceRefresh_fetchedNewTokenOnce()
throws Exception {
public void testGetToken_multipleCallsDoNotForceRefresh_fetchedNewTokenOnce() throws Exception {
// Update local storage with a EXPIRED_AUTH_TOKEN_ENTRY to validate the flow of multiple tasks
// triggered simultaneously. Task2 waits for Task1 to complete. On task1 completion, task2 reads
// the UPDATED_AUTH_TOKEN_FID_ENTRY generated by Task1.
Expand All @@ -670,11 +665,11 @@ public void testGetAuthToken_multipleCallsDoNotForceRefresh_fetchedNewTokenOnce(

FirebaseInstallations firebaseInstallations = getFirebaseInstallations();

// Call getAuthToken multiple times with DO_NOT_FORCE_REFRESH option
// Call getToken multiple times with DO_NOT_FORCE_REFRESH option
Task<InstallationTokenResult> task1 =
firebaseInstallations.getAuthToken(FirebaseInstallationsApi.DO_NOT_FORCE_REFRESH);
firebaseInstallations.getToken(FirebaseInstallationsApi.DO_NOT_FORCE_REFRESH);
Task<InstallationTokenResult> task2 =
firebaseInstallations.getAuthToken(FirebaseInstallationsApi.DO_NOT_FORCE_REFRESH);
firebaseInstallations.getToken(FirebaseInstallationsApi.DO_NOT_FORCE_REFRESH);

Tasks.await(Tasks.whenAllComplete(task1, task2));

Expand All @@ -689,10 +684,10 @@ public void testGetAuthToken_multipleCallsDoNotForceRefresh_fetchedNewTokenOnce(
}

@Test
public void testGetAuthToken_multipleCallsForceRefresh_fetchedNewTokenTwice() throws Exception {
public void testGetToken_multipleCallsForceRefresh_fetchedNewTokenTwice() throws Exception {
persistedInstallation.insertOrUpdatePersistedInstallationEntry(REGISTERED_INSTALLATION_ENTRY);
// Use a mock ServiceClient for network calls with delay(500ms) to ensure first task is not
// completed before the second task starts. Hence, we can test multiple calls to getAuthToken()
// completed before the second task starts. Hence, we can test multiple calls to getToken()
// and verify one task waits for another task to complete.

doAnswer(
Expand All @@ -719,11 +714,11 @@ public void testGetAuthToken_multipleCallsForceRefresh_fetchedNewTokenTwice() th

FirebaseInstallations firebaseInstallations = getFirebaseInstallations();

// Call getAuthToken multiple times with FORCE_REFRESH option.
// Call getToken multiple times with FORCE_REFRESH option.
Task<InstallationTokenResult> task1 =
firebaseInstallations.getAuthToken(FirebaseInstallationsApi.FORCE_REFRESH);
firebaseInstallations.getToken(FirebaseInstallationsApi.FORCE_REFRESH);
Task<InstallationTokenResult> task2 =
firebaseInstallations.getAuthToken(FirebaseInstallationsApi.FORCE_REFRESH);
firebaseInstallations.getToken(FirebaseInstallationsApi.FORCE_REFRESH);
Tasks.await(Tasks.whenAllComplete(task1, task2));

// As we cannot ensure which task got executed first, verifying with both expected values
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void hasFid(String fid) {
}

public void hasAuthToken(String authToken) {
check("getAuthToken()").that(actual.getAuthToken()).isEqualTo(authToken);
check("getToken()").that(actual.getAuthToken()).isEqualTo(authToken);
}

public void hasRefreshToken(String refreshToken) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public Task<String> getId() {
*/
@NonNull
@Override
public Task<InstallationTokenResult> getAuthToken(@AuthTokenOption int authTokenOption) {
public Task<InstallationTokenResult> getToken(@AuthTokenOption int authTokenOption) {
Task<InstallationTokenResult> task = addGetAuthTokenListener(authTokenOption);
executor.execute(this::doRegistration);
return task;
Expand Down