Skip to content

Commit

Permalink
fix: broken tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ttypic committed Mar 20, 2024
1 parent 53b4ae4 commit cc79da5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ public class Options {
activationContext.setAbly(rest);
rest.setAndroidContext(context);

DebugOptions anonymousAblyOptions = new DebugOptions();
anonymousAblyOptions.httpListener = httpTracker;
AblyRest anonymousAbly = new AblyRest(anonymousAblyOptions);
activationContext.setAnonymousAbly(anonymousAbly);

adminRest = new AblyRest(options);
adminRest.auth.authorize(new Auth.TokenParams() {{
clientId = Auth.WILDCARD_CLIENTID;
Expand Down
21 changes: 21 additions & 0 deletions android/src/main/java/io/ably/lib/push/ActivationContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

import androidx.annotation.VisibleForTesting;
import com.google.firebase.messaging.FirebaseMessaging;

import java.util.WeakHashMap;

import io.ably.lib.rest.AblyRest;
import io.ably.lib.types.AblyException;
import io.ably.lib.types.Callback;
import io.ably.lib.types.ClientOptions;
import io.ably.lib.types.ErrorInfo;
import io.ably.lib.types.RegistrationToken;
import io.ably.lib.util.Log;
Expand Down Expand Up @@ -75,6 +77,24 @@ AblyRest getAbly() throws AblyException {
return (ably = new AblyRest(deviceIdentityToken));
}

@VisibleForTesting
public void setAnonymousAbly(AblyRest ably) {
this.anonymousAbly = ably;
}

/**
* @return AblyRest instance without any options including key or token auth. We use this instance to perform
* deregistration calls in push activation flow.
*/
AblyRest getAnonymousAbly() throws AblyException {
if (anonymousAbly == null) {
ClientOptions options = new ClientOptions();
options.authCallback = params -> null;
anonymousAbly = new AblyRest(options);
}
return anonymousAbly;
}

public boolean setClientId(String clientId, boolean propagateGotPushDeviceDetails) {
Log.v(TAG, "setClientId(): clientId=" + clientId + ", propagateGotPushDeviceDetails=" + propagateGotPushDeviceDetails);
boolean updated = !clientId.equals(this.clientId);
Expand Down Expand Up @@ -168,6 +188,7 @@ public static void setActivationContext(Context applicationContext, ActivationCo
}

protected AblyRest ably;
private AblyRest anonymousAbly;
protected String clientId;
protected ActivationStateMachine activationStateMachine;
protected LocalDevice localDevice;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import io.ably.lib.rest.DeviceDetails;
import io.ably.lib.types.AblyException;
import io.ably.lib.types.Callback;
import io.ably.lib.types.ClientOptions;
import io.ably.lib.types.ErrorInfo;
import io.ably.lib.types.Param;
import io.ably.lib.types.RegistrationToken;
Expand Down Expand Up @@ -753,7 +752,7 @@ private void deregister() {
final AblyRest ably;
try {
// RSH3d2b: use `deviceIdentityToken` to perform request
ably = new AblyRest(new ClientOptions());
ably = activationContext.getAnonymousAbly();
} catch(AblyException ae) {
ErrorInfo reason = ae.errorInfo;
Log.e(TAG, "exception registering " + device.id + ": " + reason.toString());
Expand Down

0 comments on commit cc79da5

Please sign in to comment.