Skip to content

Commit

Permalink
Merge branch 'main' into 574-RSC7c-addRequestIds-clientOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-morek committed Jul 28, 2021
2 parents 05f2999 + 4a785a4 commit 636842a
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 59 deletions.
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ tasks.withType(com.android.build.gradle.internal.tasks.AndroidTestTask) { task -
apply from: '../dependencies.gradle'
apply from: './dependencies.gradle'
dependencies {
implementation 'com.google.firebase:firebase-messaging:17.3.4'
implementation 'com.google.firebase:firebase-messaging:22.0.0'
androidTestImplementation 'com.android.support.test:runner:0.5'
androidTestImplementation 'com.android.support.test:rules:0.5'
androidTestImplementation 'com.crittercism.dexmaker:dexmaker:1.4'
Expand Down
11 changes: 5 additions & 6 deletions android/src/main/java/io/ably/lib/push/ActivationContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
import android.preference.PreferenceManager;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.FirebaseApp;
import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.iid.InstanceIdResult;
import com.google.firebase.installations.FirebaseInstallations;
import com.google.firebase.installations.InstallationTokenResult;
import io.ably.lib.rest.AblyRest;
import io.ably.lib.types.AblyException;
import io.ably.lib.types.Callback;
Expand Down Expand Up @@ -151,10 +150,10 @@ public static ActivationContext getActivationContext(Context applicationContext,

protected void getRegistrationToken(final Callback<String> callback) {
Log.v(TAG, "getRegistrationToken(): callback=" + callback);
FirebaseInstanceId.getInstance().getInstanceId()
.addOnCompleteListener(new OnCompleteListener<InstanceIdResult>() {
FirebaseInstallations.getInstance().getToken(true)
.addOnCompleteListener(new OnCompleteListener<InstallationTokenResult>() {
@Override
public void onComplete(Task<InstanceIdResult> task) {
public void onComplete(Task<InstallationTokenResult> task) {
Log.v(TAG, "getRegistrationToken(): firebase called onComplete(): task=" + task);
if(task.isSuccessful()) {
/* Get new Instance ID token */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.support.v4.content.LocalBroadcastManager;

import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import com.google.gson.JsonObject;

import java.lang.reflect.Constructor;
Expand Down
3 changes: 1 addition & 2 deletions lib/src/main/java/io/ably/lib/rest/Auth.java
Original file line number Diff line number Diff line change
Expand Up @@ -868,8 +868,7 @@ public void onAuthError(ErrorInfo err) {

/* decide default auth method (spec: RSA4) */
if(authOptions.key != null) {
if(options.clientId == null &&
!options.useTokenAuth &&
if(!options.useTokenAuth &&
options.token == null &&
options.tokenDetails == null &&
options.authCallback == null &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ private synchronized void schedule(TimerTask task, long delay) {
}

public String toString() {
return WebSocketTransport.class.getName() + " [" + getURL() + "]";
return WebSocketTransport.class.getName() + " {" + getURL() + "}";
}

public String getURL() {
Expand Down
28 changes: 3 additions & 25 deletions lib/src/main/java/io/ably/lib/types/Capability.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,37 +59,15 @@ private Capability(JsonObject json) {
* it is wholly replaced by the given set of operations.
*
* @param resource the resource string
* @param ops a String[] of the operations permitted for this resource;
* the array does not need to be sorted
* @param ops a String varargs of the operations permitted for this resource;
* the arguments do not need to be sorted
*/
public void addResource(String resource, String[] ops) {
public void addResource(String resource, String... ops) {
JsonArray jsonOps = (JsonArray)gson.toJsonTree(ops);
json.add(resource, jsonOps);
dirty = true;
}

/**
* Add a resource to an existing Capability instance with the
* given single operation. If the resource already exists,
* it is wholly replaced by the given set of operations.
*
* @param resource the resource string
* @param op a single operation String to be permitted for this resource;
*/
public void addResource(String resource, String op) {
addResource(resource, new String[]{op});
}

/**
* Add a resource to an existing Capability instance with an
* empty set of operations. If the resource already exists,
* the effect is to reset its set of operations to empty.
*
* @param resource the resource string
*/
public void addResource(String resource) {
addResource(resource, new String[0]);
}
/**
* Remove a resource from an existing Capability instance
*
Expand Down
4 changes: 2 additions & 2 deletions lib/src/main/java/io/ably/lib/types/ErrorInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public ErrorInfo(String message, int statusCode, int code) {
}

public String toString() {
StringBuilder result = new StringBuilder("[ErrorInfo");
StringBuilder result = new StringBuilder("{ErrorInfo");
result.append(" message=").append(logMessage());
if(code > 0) {
result.append(" code=").append(code);
Expand All @@ -77,7 +77,7 @@ public String toString() {
if(href != null) {
result.append(" href=").append(href);
}
result.append(']');
result.append('}');
return result.toString();
}

Expand Down
4 changes: 2 additions & 2 deletions lib/src/main/java/io/ably/lib/types/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ public Message(String name, Object data, String clientId, MessageExtras extras)
* @return string
*/
public String toString() {
StringBuilder result = new StringBuilder("[Message");
StringBuilder result = new StringBuilder("{Message");
super.getDetails(result);
if(name != null)
result.append(" name=").append(name);
result.append(']');
result.append('}');
return result.toString();
}

Expand Down
4 changes: 2 additions & 2 deletions lib/src/main/java/io/ably/lib/types/PresenceMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ public PresenceMessage(Action action, String clientId, Object data) {
* @return string
*/
public String toString() {
StringBuilder result = new StringBuilder("[PresenceMessage");
StringBuilder result = new StringBuilder("{PresenceMessage");
super.getDetails(result);
result.append(" action=").append(action.name());
result.append(']');
result.append('}');
return result.toString();
}

Expand Down
10 changes: 5 additions & 5 deletions lib/src/test/java/io/ably/lib/test/rest/RestAuthTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,20 +191,20 @@ public String getTokenRequest(TokenParams params) throws AblyException {
}

/**
* Init library with a key and clientId; expect token auth to be chosen
* Spec: RSA4, RSC17, RSA7b1
* Init library with a key and clientId; expect basic auth to be chosen
* Spec: RSC17, RSA7b1
*/
@Test
public void authinit_clientId_implies_token() {
public void authinit_clientId_auth_basic() {
try {
ClientOptions opts = createOptions(testVars.keys[0].keyStr);
opts.clientId = "testClientId";
AblyRest ably = new AblyRest(opts);
assertEquals("Unexpected Auth method mismatch", ably.auth.getAuthMethod(), AuthMethod.token);
assertEquals("Unexpected Auth method mismatch", ably.auth.getAuthMethod(), AuthMethod.basic);
assertEquals("Unexpected clientId mismatch", ably.auth.clientId, "testClientId");
} catch (AblyException e) {
e.printStackTrace();
fail("authinit_clientId_implies_token: Unexpected exception instantiating library");
fail("authinit_clientId_auth_basic: Unexpected exception instantiating library");
}
}

Expand Down
24 changes: 12 additions & 12 deletions lib/src/test/java/io/ably/lib/test/rest/RestCapabilityTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public void authcapability3() {
}

/**
* Non-empty ops intersection
* Non-empty ops intersection
*/
@Test
public void authcapability4() {
Expand All @@ -116,7 +116,7 @@ public void authcapability4() {
authOptions.key = key.keyStr;
TokenParams tokenParams = new TokenParams();
Capability requestedCapability = new Capability();
requestedCapability.addResource("channel2", new String[]{"presence", "subscribe"});
requestedCapability.addResource("channel2", "presence", "subscribe");
tokenParams.capability = requestedCapability.toString();
TokenDetails tokenDetails = ably.auth.requestToken(tokenParams, authOptions);
Capability expectedCapability = new Capability();
Expand All @@ -130,7 +130,7 @@ public void authcapability4() {
}

/**
* Non-empty paths intersection
* Non-empty paths intersection
*/
@Test
public void authcapability5() {
Expand All @@ -140,8 +140,8 @@ public void authcapability5() {
authOptions.key = key.keyStr;
TokenParams tokenParams = new TokenParams();
Capability requestedCapability = new Capability();
requestedCapability.addResource("channel2", new String[]{"presence", "subscribe"});
requestedCapability.addResource("channelx", new String[]{"presence", "subscribe"});
requestedCapability.addResource("channel2", "presence", "subscribe");
requestedCapability.addResource("channelx", "presence", "subscribe");
tokenParams.capability = requestedCapability.toString();
TokenDetails tokenDetails = ably.auth.requestToken(tokenParams, authOptions);
Capability expectedCapability = new Capability();
Expand All @@ -155,7 +155,7 @@ public void authcapability5() {
}

/**
* Wildcard ops intersection
* Wildcard ops intersection
*/
@Test
public void authcapability6() {
Expand All @@ -169,7 +169,7 @@ public void authcapability6() {
tokenParams.capability = requestedCapability.toString();
TokenDetails tokenDetails = ably.auth.requestToken(tokenParams, authOptions);
Capability expectedCapability = new Capability();
expectedCapability.addResource("channel2", new String[]{"publish", "subscribe"});
expectedCapability.addResource("channel2", "publish", "subscribe");
assertNotNull("Expected token value", tokenDetails.token);
assertEquals("Unexpected capability", tokenDetails.capability, expectedCapability.toString());
} catch (AblyException e) {
Expand All @@ -185,11 +185,11 @@ public void authcapability7() {
authOptions.key = key.keyStr;
TokenParams tokenParams = new TokenParams();
Capability requestedCapability = new Capability();
requestedCapability.addResource("channel6", new String[]{"publish", "subscribe"});
requestedCapability.addResource("channel6", "publish", "subscribe");
tokenParams.capability = requestedCapability.toString();
TokenDetails tokenDetails = ably.auth.requestToken(tokenParams, authOptions);
Capability expectedCapability = new Capability();
expectedCapability.addResource("channel6", new String[]{"publish", "subscribe"});
expectedCapability.addResource("channel6", "publish", "subscribe");
assertNotNull("Expected token value", tokenDetails.token);
assertEquals("Unexpected capability", tokenDetails.capability, expectedCapability.toString());
} catch (AblyException e) {
Expand All @@ -199,7 +199,7 @@ public void authcapability7() {
}

/**
* Wildcard resources intersection
* Wildcard resources intersection
*/
@Test
public void authcapability8() {
Expand Down Expand Up @@ -276,7 +276,7 @@ public void authinvalid0() {
public void authinvalid1() {
TokenParams tokenParams = new TokenParams();
Capability invalidCapability = new Capability();
invalidCapability.addResource("channel0", new String[]{"*", "publish"});
invalidCapability.addResource("channel0", "*", "publish");
tokenParams.capability = invalidCapability.toString();
try {
ably.auth.requestToken(tokenParams, null);
Expand All @@ -289,7 +289,7 @@ public void authinvalid1() {
public void authinvalid2() {
TokenParams tokenParams = new TokenParams();
Capability invalidCapability = new Capability();
invalidCapability.addResource("channel0", new String[0]);
invalidCapability.addResource("channel0");
tokenParams.capability = invalidCapability.toString();
try {
ably.auth.requestToken(tokenParams, null);
Expand Down

0 comments on commit 636842a

Please sign in to comment.