From 4923b78e3e724b635faa9a661e3e20e4d342925a Mon Sep 17 00:00:00 2001 From: Max Presman Date: Wed, 21 Sep 2016 11:06:08 -0700 Subject: [PATCH 1/7] add proxy support --- src/main/java/com/pubnub/api/PNConfiguration.java | 7 +++++++ src/main/java/com/pubnub/api/managers/RetrofitManager.java | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/src/main/java/com/pubnub/api/PNConfiguration.java b/src/main/java/com/pubnub/api/PNConfiguration.java index ebc9362c5..6f7e54f29 100644 --- a/src/main/java/com/pubnub/api/PNConfiguration.java +++ b/src/main/java/com/pubnub/api/PNConfiguration.java @@ -9,6 +9,7 @@ import lombok.Setter; import lombok.experimental.Accessors; +import java.net.Proxy; import java.util.UUID; @Getter @@ -97,6 +98,12 @@ public class PNConfiguration { @Setter private PNReconnectionPolicy reconnectionPolicy; + /** + * Proxy configuration which will be passed to the networking layer. + */ + @Setter + private Proxy proxy; + /** * Initialize the PNConfiguration with default values */ diff --git a/src/main/java/com/pubnub/api/managers/RetrofitManager.java b/src/main/java/com/pubnub/api/managers/RetrofitManager.java index 5a47d8a54..3b9252b6f 100644 --- a/src/main/java/com/pubnub/api/managers/RetrofitManager.java +++ b/src/main/java/com/pubnub/api/managers/RetrofitManager.java @@ -49,6 +49,10 @@ private OkHttpClient createOkHttpClient(int requestTimeout, int connectTimeOut) httpClient.addInterceptor(logging); } + if (pubnub.getConfiguration().getProxy() != null) { + httpClient.proxy(pubnub.getConfiguration().getProxy()); + } + return httpClient.build(); } From e4628ca6431b2f2865bb4d158985a483c433199e Mon Sep 17 00:00:00 2001 From: Marcelo Marques Inacio Date: Mon, 3 Oct 2016 09:59:00 -0300 Subject: [PATCH 2/7] instanceId and requestId --- .../java/com/pubnub/api/PNConfiguration.java | 20 +++++ src/main/java/com/pubnub/api/PubNub.java | 19 ++++- .../com/pubnub/api/endpoints/Endpoint.java | 8 ++ .../com/pubnub/api/endpoints/TestHarness.java | 6 ++ .../endpoints/access/AuditEndpointTest.java | 12 ++- .../endpoints/access/GrantEndpointTest.java | 84 ++++++++++++++----- 6 files changed, 124 insertions(+), 25 deletions(-) diff --git a/src/main/java/com/pubnub/api/PNConfiguration.java b/src/main/java/com/pubnub/api/PNConfiguration.java index 6f7e54f29..a7b1c3bbe 100644 --- a/src/main/java/com/pubnub/api/PNConfiguration.java +++ b/src/main/java/com/pubnub/api/PNConfiguration.java @@ -15,12 +15,27 @@ @Getter @Setter @Accessors(chain = true) + public class PNConfiguration { private static final int PRESENCE_TIMEOUT = 300; private static final int NON_SUBSCRIBE_REQUEST_TIMEOUT = 10; private static final int SUBSCRIBE_TIMEOUT = 310; private static final int CONNECT_TIMEOUT = 5; + /** + * Set to true to send a UUID for PubNub instance + */ + @Getter + @Setter(AccessLevel.NONE) + private boolean includeInstanceIdentifier; + + /** + * Set to true to send a UUID on each request + */ + @Getter + @Setter(AccessLevel.NONE) + private boolean includeRequestIdentifier; + /** * By default, the origin is pointing directly to PubNub servers. If a proxy origin is needed, set a custom * origin using this parameter. @@ -122,6 +137,11 @@ public PNConfiguration() { reconnectionPolicy = PNReconnectionPolicy.NONE; secure = true; + + includeInstanceIdentifier = true; + + includeRequestIdentifier = true; + } /** diff --git a/src/main/java/com/pubnub/api/PubNub.java b/src/main/java/com/pubnub/api/PubNub.java index 1373d6563..9a3ad33a6 100644 --- a/src/main/java/com/pubnub/api/PubNub.java +++ b/src/main/java/com/pubnub/api/PubNub.java @@ -33,6 +33,7 @@ import java.util.Date; import java.util.List; +import java.util.UUID; @Getter @@ -40,7 +41,8 @@ public class PubNub { private PNConfiguration configuration; - + @Getter(AccessLevel.NONE) + private String instanceId; @Getter(AccessLevel.NONE) private SubscriptionManager subscriptionManager; @Getter(AccessLevel.NONE) @@ -62,6 +64,7 @@ public PubNub(final PNConfiguration initialConfig) { this.retrofitManager = new RetrofitManager(this); this.subscriptionManager = new SubscriptionManager(this, retrofitManager); this.publishSequenceManager = new PublishSequenceManager(MAX_SEQUENCE); + instanceId = UUID.randomUUID().toString(); } public String getBaseUrl() { @@ -229,6 +232,20 @@ public int getTimestamp() { return (int) ((new Date().getTime()) / TIMESTAMP_DIVIDER); } + /** + * @return instance uuid. + */ + public String getInstanceId() { + return instanceId; + } + + /** + * @return request uuid. + */ + public String getRequestId() { + return UUID.randomUUID().toString(); + } + /** * @return version of the SDK. */ diff --git a/src/main/java/com/pubnub/api/endpoints/Endpoint.java b/src/main/java/com/pubnub/api/endpoints/Endpoint.java index efb4f6201..d4b68e12b 100644 --- a/src/main/java/com/pubnub/api/endpoints/Endpoint.java +++ b/src/main/java/com/pubnub/api/endpoints/Endpoint.java @@ -283,6 +283,14 @@ protected final Map createBaseParams() { params.put("pnsdk", "PubNub-Java-Unified/".concat(this.pubnub.getVersion())); params.put("uuid", this.pubnub.getConfiguration().getUuid()); + if (this.pubnub.getConfiguration().isIncludeInstanceIdentifier()) { + params.put("instanceId", pubnub.getInstanceId()); + } + + if (this.pubnub.getConfiguration().isIncludeRequestIdentifier()) { + params.put("requestId", pubnub.getRequestId()); + } + // add the auth key for publish and subscribe. if (this.pubnub.getConfiguration().getAuthKey() != null && isAuthRequired()) { params.put("auth", pubnub.getConfiguration().getAuthKey()); diff --git a/src/test/java/com/pubnub/api/endpoints/TestHarness.java b/src/test/java/com/pubnub/api/endpoints/TestHarness.java index a0b709888..8533604ef 100644 --- a/src/test/java/com/pubnub/api/endpoints/TestHarness.java +++ b/src/test/java/com/pubnub/api/endpoints/TestHarness.java @@ -31,6 +31,12 @@ public String getVersion() { return "suchJava"; } + @Override + public String getInstanceId() { return "PubNubInstanceId"; } + + @Override + public String getRequestId() { return "PubNubRequestId"; } + } return new MockedTimePubNub(pnConfiguration); diff --git a/src/test/java/com/pubnub/api/endpoints/access/AuditEndpointTest.java b/src/test/java/com/pubnub/api/endpoints/access/AuditEndpointTest.java index 6a1542c7b..62270f18f 100644 --- a/src/test/java/com/pubnub/api/endpoints/access/AuditEndpointTest.java +++ b/src/test/java/com/pubnub/api/endpoints/access/AuditEndpointTest.java @@ -48,9 +48,11 @@ public void testSuccessChannelGroupSync() throws PubNubException { stubFor(get(urlPathEqualTo("/v1/auth/audit/sub-key/mySubscribeKey")) .withQueryParam("pnsdk", matching("PubNub-Java-Unified/suchJava")) + .withQueryParam("instanceId", matching("PubNubInstanceId")) + .withQueryParam("requestId", matching("PubNubRequestId")) + .withQueryParam("signature", matching("dVle3aE_grdzKypoEegdNSZs_CXpJQJEcnqcM0nMH0Q%3D%0A")) .withQueryParam("channel-group", matching("cg1")) .withQueryParam("auth", matching("key1")) - .withQueryParam("signature", matching("rXy69MNT1vceNs3Ob6HnjShUAzCV5x4OumSG1lSPL6s%3D%0A")) .withQueryParam("uuid", matching("myUUID")) .withQueryParam("timestamp", matching("1337")) .willReturn(aResponse().withBody("{\"message\":\"Success\",\"payload\":{\"level\":\"channel-group+auth\",\"subscribe_key\":\"sub-c-82ab2196-b64f-11e5-8622-0619f8945a4f\",\"channel-group\":\"cg2\",\"auths\":{\"key1\":{\"r\":1,\"m\":1,\"w\":1}}},\"service\":\"Access Manager\",\"status\":200}"))); @@ -76,7 +78,9 @@ public void testSuccessChannelSync() throws PubNubException { .withQueryParam("pnsdk", matching("PubNub-Java-Unified/suchJava")) .withQueryParam("channel", matching("ch1")) .withQueryParam("auth", matching("key1")) - .withQueryParam("signature", matching("oICb_S5OubabiqrEA9vDqQ-Ri4PdztWLs6__fQQP_Gs%3D%0A")) + .withQueryParam("instanceId", matching("PubNubInstanceId")) + .withQueryParam("requestId", matching("PubNubRequestId")) + .withQueryParam("signature", matching("4WIVMIc007EqwYGrqyJuMy5qf-gvtdopDjfaXEa1zOs%3D%0A")) .withQueryParam("uuid", matching("myUUID")) .withQueryParam("timestamp", matching("1337")) .willReturn(aResponse().withBody("{\"message\":\"Success\",\"payload\":{\"level\":\"user\",\"subscribe_key\":\"sub-c-82ab2196-b64f-11e5-8622-0619f8945a4f\",\"channel\":\"ch1\",\"auths\":{\"key1\":{\"r\":1,\"m\":1,\"w\":1}}},\"service\":\"Access Manager\",\"status\":200}"))); @@ -143,7 +147,9 @@ public void testIsAuthRequiredSuccessSync() throws IOException, PubNubException, .withQueryParam("pnsdk", matching("PubNub-Java-Unified/suchJava")) .withQueryParam("channel-group", matching("cg1")) .withQueryParam("auth", matching("key1")) - .withQueryParam("signature", matching("rXy69MNT1vceNs3Ob6HnjShUAzCV5x4OumSG1lSPL6s%3D%0A")) + .withQueryParam("instanceId", matching("PubNubInstanceId")) + .withQueryParam("requestId", matching("PubNubRequestId")) + .withQueryParam("signature", matching("dVle3aE_grdzKypoEegdNSZs_CXpJQJEcnqcM0nMH0Q%3D%0A")) .withQueryParam("uuid", matching("myUUID")) .withQueryParam("timestamp", matching("1337")) .willReturn(aResponse().withBody("{\"message\":\"Success\",\"payload\":{\"level\":\"channel-group+auth\",\"subscribe_key\":\"sub-c-82ab2196-b64f-11e5-8622-0619f8945a4f\",\"channel-group\":\"cg2\",\"auths\":{\"key1\":{\"r\":1,\"m\":1,\"w\":1}}},\"service\":\"Access Manager\",\"status\":200}"))); diff --git a/src/test/java/com/pubnub/api/endpoints/access/GrantEndpointTest.java b/src/test/java/com/pubnub/api/endpoints/access/GrantEndpointTest.java index 3499f0d54..125f2c70a 100644 --- a/src/test/java/com/pubnub/api/endpoints/access/GrantEndpointTest.java +++ b/src/test/java/com/pubnub/api/endpoints/access/GrantEndpointTest.java @@ -47,7 +47,9 @@ public void NoGroupsOneChannelOneKeyTest() throws PubNubException { .withQueryParam("pnsdk", matching("PubNub-Java-Unified/suchJava")) .withQueryParam("channel", matching("ch1")) .withQueryParam("auth", matching("key1")) - .withQueryParam("signature", matching("HlyfXDFhdgNhKfBzGaouxh2T2SRimm4bVq_JVKLRPQI%3D%0A")) + .withQueryParam("instanceId", matching("PubNubInstanceId")) + .withQueryParam("requestId", matching("PubNubRequestId")) + .withQueryParam("signature", matching("Sw4LDrBsxjXYgzw6H2ww_omDFmT5Sozd2Bd0NDRQ7GA%3D%0A")) .withQueryParam("uuid", matching("myUUID")) .withQueryParam("timestamp", matching("1337")) .withQueryParam("r", matching("0")) @@ -72,7 +74,9 @@ public void NoGroupsOneChannelTwoKeyTest() throws PubNubException { .withQueryParam("pnsdk", matching("PubNub-Java-Unified/suchJava")) .withQueryParam("channel", matching("ch1")) .withQueryParam("auth", matching("key1,key2")) - .withQueryParam("signature", matching("sbcQS0RjU7uq0Q9YqN7HFJO26SlgVXPejhmVJJ2w5OU%3D%0A")) + .withQueryParam("instanceId", matching("PubNubInstanceId")) + .withQueryParam("requestId", matching("PubNubRequestId")) + .withQueryParam("signature", matching("LY9uFbCRnA1fHZLd2kBsIdM9LocwnVTIHxwp3BwQ5XQ%3D%0A")) .withQueryParam("uuid", matching("myUUID")) .withQueryParam("timestamp", matching("1337")) .withQueryParam("r", matching("0")) @@ -97,7 +101,9 @@ public void NoGroupsTwoChannelOneKeyTest() throws PubNubException { .withQueryParam("pnsdk", matching("PubNub-Java-Unified/suchJava")) .withQueryParam("channel", matching("ch1,ch2")) .withQueryParam("auth", matching("key1")) - .withQueryParam("signature", matching("pizC0huUiyQFdOnNDGxjU9xX6b9GFcslSm6bqfrimq4%3D%0A")) + .withQueryParam("instanceId", matching("PubNubInstanceId")) + .withQueryParam("requestId", matching("PubNubRequestId")) + .withQueryParam("signature", matching("_z51OsbDp9kvYfKQZUJoiyo82_QuAVZ7JyKi9zoGFAc%3D%0A")) .withQueryParam("uuid", matching("myUUID")) .withQueryParam("timestamp", matching("1337")) .withQueryParam("r", matching("0")) @@ -123,7 +129,9 @@ public void NoGroupsTwoChannelTwoKeyTest() throws PubNubException { .withQueryParam("pnsdk", matching("PubNub-Java-Unified/suchJava")) .withQueryParam("channel", matching("ch1,ch2")) .withQueryParam("auth", matching("key1,key2")) - .withQueryParam("signature", matching("SRklo_IoAeNbvmp_xQV0kwL8vLz2vTEk14umB7v6K-w%3D%0A")) + .withQueryParam("instanceId", matching("PubNubInstanceId")) + .withQueryParam("requestId", matching("PubNubRequestId")) + .withQueryParam("signature", matching("_TV8Gcpvr6L1W-9cARyGXMj3x3VIJwP1_Cuz3oDDHRE%3D%0A")) .withQueryParam("uuid", matching("myUUID")) .withQueryParam("timestamp", matching("1337")) .withQueryParam("r", matching("0")) @@ -151,7 +159,9 @@ public void OneGroupNoChannelOneKey() throws PubNubException { .withQueryParam("pnsdk", matching("PubNub-Java-Unified/suchJava")) .withQueryParam("channel-group", matching("cg1")) .withQueryParam("auth", matching("key1")) - .withQueryParam("signature", matching("kqLDzzhvhUQ9Ri3j2xRFDvMYDbLQ2aM3erz52QL_IQ0%3D%0A")) + .withQueryParam("instanceId", matching("PubNubInstanceId")) + .withQueryParam("requestId", matching("PubNubRequestId")) + .withQueryParam("signature", matching("JsJT8pcHUKP3OBpkuNznbmxRejYC_DQBZldbpphM1sk%3D%0A")) .withQueryParam("uuid", matching("myUUID")) .withQueryParam("timestamp", matching("1337")) .withQueryParam("r", matching("0")) @@ -176,7 +186,9 @@ public void OneGroupNoChannelTwoKey() throws PubNubException { .withQueryParam("pnsdk", matching("PubNub-Java-Unified/suchJava")) .withQueryParam("channel-group", matching("cg1")) .withQueryParam("auth", matching("key1,key2")) - .withQueryParam("signature", matching("ET_b6B8vPfdyvwM1eJLitDERcwykGhTkuQNeryH7q5o%3D%0A")) + .withQueryParam("instanceId", matching("PubNubInstanceId")) + .withQueryParam("requestId", matching("PubNubRequestId")) + .withQueryParam("signature", matching("BlTyZ9ysUV8JEU1BMps8Kfjqbu3m0dsUDRHlbnNIX5Y%3D%0A")) .withQueryParam("uuid", matching("myUUID")) .withQueryParam("timestamp", matching("1337")) .withQueryParam("r", matching("0")) @@ -203,7 +215,9 @@ public void OneGroupOneChannelOneKey() throws PubNubException { .withQueryParam("channel", matching("ch1")) .withQueryParam("channel-group", matching("cg1")) .withQueryParam("auth", matching("key1")) - .withQueryParam("signature", matching("QqOQSjo6VEG4JUp6NSBjc4SQ5lqTPoPGeOgzuXF6fbE%3D%0A")) + .withQueryParam("instanceId", matching("PubNubInstanceId")) + .withQueryParam("requestId", matching("PubNubRequestId")) + .withQueryParam("signature", matching("CVKPMHlOKHpnjdM-yitToj3jC2Betd9QTyATN4GCgfU%3D%0A")) .withQueryParam("uuid", matching("myUUID")) .withQueryParam("timestamp", matching("1337")) .withQueryParam("r", matching("0")) @@ -232,7 +246,9 @@ public void OneGroupOneChannelTwoKey() throws PubNubException { .withQueryParam("channel", matching("ch1")) .withQueryParam("channel-group", matching("cg1")) .withQueryParam("auth", matching("key1,key2")) - .withQueryParam("signature", matching("G3-cvSBeaQmwWabOOoHMxIH78MlvcOdGJS83z6cH7RY%3D%0A")) + .withQueryParam("instanceId", matching("PubNubInstanceId")) + .withQueryParam("requestId", matching("PubNubRequestId")) + .withQueryParam("signature", matching("p21l4hlci0VGsQ_cDHfLubFALgtunt6ote7tBx4bpUU%3D%0A")) .withQueryParam("uuid", matching("myUUID")) .withQueryParam("timestamp", matching("1337")) .withQueryParam("r", matching("0")) @@ -263,7 +279,9 @@ public void OneGroupTwoChannelOneKey() throws PubNubException { .withQueryParam("channel", matching("ch1,ch2")) .withQueryParam("channel-group", matching("cg1")) .withQueryParam("auth", matching("key1")) - .withQueryParam("signature", matching("LYQdmYjV0Gxbu_1uhey5wPyIJ2cZPTjp7Grc0oUwTl4%3D%0A")) + .withQueryParam("instanceId", matching("PubNubInstanceId")) + .withQueryParam("requestId", matching("PubNubRequestId")) + .withQueryParam("signature", matching("ZEp63rTMmTh5N-uqN6UZuDP5GKE-b7SLwOrdi3yiBLM%3D%0A")) .withQueryParam("uuid", matching("myUUID")) .withQueryParam("timestamp", matching("1337")) .withQueryParam("r", matching("0")) @@ -293,7 +311,9 @@ public void OneGroupTwoChannelTwoKey() throws PubNubException { .withQueryParam("channel", matching("ch1,ch2")) .withQueryParam("channel-group", matching("cg1")) .withQueryParam("auth", matching("key1,key2")) - .withQueryParam("signature", matching("iMUJd9GHcLUeBpIgKD3JLUQ-B3t0XGa2D-IWrrV30_o%3D%0A")) + .withQueryParam("instanceId", matching("PubNubInstanceId")) + .withQueryParam("requestId", matching("PubNubRequestId")) + .withQueryParam("signature", matching("Kcl_Ba5CPDYXlhLcXyzhVHZlWTDaSRV5syEQjq5IGbU%3D%0A")) .withQueryParam("uuid", matching("myUUID")) .withQueryParam("timestamp", matching("1337")) .withQueryParam("r", matching("0")) @@ -326,7 +346,9 @@ public void TwoGroupNoChannelOneKey() throws PubNubException { .withQueryParam("pnsdk", matching("PubNub-Java-Unified/suchJava")) .withQueryParam("channel-group", matching("cg1,cg2")) .withQueryParam("auth", matching("key1")) - .withQueryParam("signature", matching("FRx_2Pes924avZU3ldKb7Ry1u86jHOztltxdlicWvyA%3D%0A")) + .withQueryParam("instanceId", matching("PubNubInstanceId")) + .withQueryParam("requestId", matching("PubNubRequestId")) + .withQueryParam("signature", matching("SLl749bJMEpxt_o7JeJdSTpLzTaq8P4aCC9jXWnDd58%3D%0A")) .withQueryParam("uuid", matching("myUUID")) .withQueryParam("timestamp", matching("1337")) .withQueryParam("r", matching("0")) @@ -353,7 +375,9 @@ public void TwoGroupNoChannelTwoKey() throws PubNubException { .withQueryParam("pnsdk", matching("PubNub-Java-Unified/suchJava")) .withQueryParam("channel-group", matching("cg1,cg2")) .withQueryParam("auth", matching("key1,key2")) - .withQueryParam("signature", matching("N5VsRLfm6PXduKXTApCEa95E99JcR9aVMecejEiUJkI%3D%0A")) + .withQueryParam("instanceId", matching("PubNubInstanceId")) + .withQueryParam("requestId", matching("PubNubRequestId")) + .withQueryParam("signature", matching("Avb_BjSWm2KsdIXNDoU__q5zfKx7qKZbsEJ6Mo6y_BU%3D%0A")) .withQueryParam("uuid", matching("myUUID")) .withQueryParam("timestamp", matching("1337")) .withQueryParam("r", matching("0")) @@ -382,7 +406,9 @@ public void TwoGroupOneChannelOneKey() throws PubNubException { .withQueryParam("channel", matching("ch1")) .withQueryParam("channel-group", matching("cg1,cg2")) .withQueryParam("auth", matching("key1")) - .withQueryParam("signature", matching("T3vn9bb7T6MG_KkST4i_80iYCAj0crgtJ-PUZVGI_Wg%3D%0A")) + .withQueryParam("instanceId", matching("PubNubInstanceId")) + .withQueryParam("requestId", matching("PubNubRequestId")) + .withQueryParam("signature", matching("wa2h4HJ0b1pWS4R6oNtUKWB5BllrkPzc8GSK44GY2l8%3D%0A")) .withQueryParam("uuid", matching("myUUID")) .withQueryParam("timestamp", matching("1337")) .withQueryParam("r", matching("0")) @@ -412,7 +438,9 @@ public void TwoGroupOneChannelTwoKey() throws PubNubException { .withQueryParam("channel", matching("ch1")) .withQueryParam("channel-group", matching("cg1,cg2")) .withQueryParam("auth", matching("key1,key2")) - .withQueryParam("signature", matching("UzjgorbyDjwBxfu0Nr5V2VJ6J9614ihHiRwZ5yU20Ek%3D%0A")) + .withQueryParam("instanceId", matching("PubNubInstanceId")) + .withQueryParam("requestId", matching("PubNubRequestId")) + .withQueryParam("signature", matching("P3grHL6O8P185puxlqJZHFUz0_CoirZcaqFlHIhf7E0%3D%0A")) .withQueryParam("uuid", matching("myUUID")) .withQueryParam("timestamp", matching("1337")) .withQueryParam("r", matching("0")) @@ -445,7 +473,9 @@ public void TwoGroupTwoChannelOneKey() throws PubNubException { .withQueryParam("pnsdk", matching("PubNub-Java-Unified/suchJava")) .withQueryParam("channel", matching("ch1,ch2")) .withQueryParam("auth", matching("key1")) - .withQueryParam("signature", matching("7znRWub4WttnrofkghqBaxSE3XeQ0ZHtZU5QZB2ofR4%3D%0A")) + .withQueryParam("instanceId", matching("PubNubInstanceId")) + .withQueryParam("requestId", matching("PubNubRequestId")) + .withQueryParam("signature", matching("UuOtPl3i-6nThXYsxuoMcMTo6RkLRriVYXQb9yH4UgY%3D%0A")) .withQueryParam("uuid", matching("myUUID")) .withQueryParam("timestamp", matching("1337")) .withQueryParam("r", matching("0")) @@ -477,7 +507,9 @@ public void TwoGroupTwoChannelTwoKey() throws PubNubException { .withQueryParam("channel", matching("ch1,ch2")) .withQueryParam("channel-group", matching("cg1,cg2")) .withQueryParam("auth", matching("key1,key2")) - .withQueryParam("signature", matching("pX82pKukTC75_ZhHkcvUQXTuCYC7iuh_h2wmWWrO7hg%3D%0A")) + .withQueryParam("instanceId", matching("PubNubInstanceId")) + .withQueryParam("requestId", matching("PubNubRequestId")) + .withQueryParam("signature", matching("yNi_IK2z0dH3MTwpQZNnUGsba5jyg9nI4PYwMP1WH74%3D%0A")) .withQueryParam("uuid", matching("myUUID")) .withQueryParam("timestamp", matching("1337")) .withQueryParam("r", matching("0")) @@ -513,7 +545,9 @@ public void NoGroupsOneChannelOneKeyTTLTest() throws PubNubException { .withQueryParam("pnsdk", matching("PubNub-Java-Unified/suchJava")) .withQueryParam("channel", matching("ch1")) .withQueryParam("auth", matching("key1")) - .withQueryParam("signature", matching("2XtpqL0DBNHCh6cKeCqxfJeq4sa8AG4vZFXT1quaVnw%3D%0A")) + .withQueryParam("instanceId", matching("PubNubInstanceId")) + .withQueryParam("requestId", matching("PubNubRequestId")) + .withQueryParam("signature", matching("uzvZ_RvrHrU0alJGZ5CYhf2i0X5jfjwCXkr4BPFiKPE%3D%0A")) .withQueryParam("uuid", matching("myUUID")) .withQueryParam("timestamp", matching("1337")) .withQueryParam("r", matching("0")) @@ -539,7 +573,9 @@ public void NoGroupsOneChannelOneReadKeyTest() throws PubNubException { .withQueryParam("pnsdk", matching("PubNub-Java-Unified/suchJava")) .withQueryParam("channel", matching("ch1")) .withQueryParam("auth", matching("key1")) - .withQueryParam("signature", matching("KgI1t0Y50H6mIZ12re8TyaMDoEx63NMHJ260kjyge38%3D%0A")) + .withQueryParam("instanceId", matching("PubNubInstanceId")) + .withQueryParam("requestId", matching("PubNubRequestId")) + .withQueryParam("signature", matching("w-pT2ZJEAp85vvIZCdKwpNG3-QW4_q7wwPMIvh8KBIw%3D%0A")) .withQueryParam("uuid", matching("myUUID")) .withQueryParam("timestamp", matching("1337")) .withQueryParam("r", matching("1")) @@ -564,7 +600,9 @@ public void NoGroupsOneChannelOneWriteKeyTest() throws PubNubException { .withQueryParam("pnsdk", matching("PubNub-Java-Unified/suchJava")) .withQueryParam("channel", matching("ch1")) .withQueryParam("auth", matching("key1")) - .withQueryParam("signature", matching("wQSMOVu0bvmyxt6F8_lc81dmsF_pz5f9VjOpe1FiB_w%3D%0A")) + .withQueryParam("instanceId", matching("PubNubInstanceId")) + .withQueryParam("requestId", matching("PubNubRequestId")) + .withQueryParam("signature", matching("me6ZZegEWBqCmjs8dNb4BmB7Y-15FV8KXfecSxm2Y0o%3D%0A")) .withQueryParam("uuid", matching("myUUID")) .withQueryParam("timestamp", matching("1337")) .withQueryParam("r", matching("0")) @@ -589,7 +627,9 @@ public void NoGroupsOneChannelOneKeyManageTest() throws PubNubException { .withQueryParam("pnsdk", matching("PubNub-Java-Unified/suchJava")) .withQueryParam("channel", matching("ch1")) .withQueryParam("auth", matching("key1")) - .withQueryParam("signature", matching("TUtUB_2F738wA1tuENkDUedkVuTwGbtGXqE1PekesHA%3D%0A")) + .withQueryParam("instanceId", matching("PubNubInstanceId")) + .withQueryParam("requestId", matching("PubNubRequestId")) + .withQueryParam("signature", matching("VNOI32TCodRd3Uzw0_gRQjbsKVnl6fGkFkXDa08hrkU%3D%0A")) .withQueryParam("uuid", matching("myUUID")) .withQueryParam("timestamp", matching("1337")) .withQueryParam("r", matching("0")) @@ -633,7 +673,9 @@ public void testIsAuthRequiredSuccessSync() throws IOException, PubNubException, .withQueryParam("pnsdk", matching("PubNub-Java-Unified/suchJava")) .withQueryParam("channel", matching("ch1")) .withQueryParam("auth", matching("key1")) - .withQueryParam("signature", matching("HlyfXDFhdgNhKfBzGaouxh2T2SRimm4bVq_JVKLRPQI%3D%0A")) + .withQueryParam("instanceId", matching("PubNubInstanceId")) + .withQueryParam("requestId", matching("PubNubRequestId")) + .withQueryParam("signature", matching("Sw4LDrBsxjXYgzw6H2ww_omDFmT5Sozd2Bd0NDRQ7GA%3D%0A")) .withQueryParam("uuid", matching("myUUID")) .withQueryParam("timestamp", matching("1337")) .withQueryParam("r", matching("0")) From 89b80b79cb2e153f3e1ba86ae3f954c3113fdde9 Mon Sep 17 00:00:00 2001 From: Max Presman Date: Mon, 3 Oct 2016 15:27:28 -0700 Subject: [PATCH 3/7] patch up variable names + endpoint test --- src/main/java/com/pubnub/api/endpoints/Endpoint.java | 4 ++-- src/test/java/com/pubnub/api/endpoints/EndpointTest.java | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/pubnub/api/endpoints/Endpoint.java b/src/main/java/com/pubnub/api/endpoints/Endpoint.java index d4b68e12b..49bef5f17 100644 --- a/src/main/java/com/pubnub/api/endpoints/Endpoint.java +++ b/src/main/java/com/pubnub/api/endpoints/Endpoint.java @@ -284,11 +284,11 @@ protected final Map createBaseParams() { params.put("uuid", this.pubnub.getConfiguration().getUuid()); if (this.pubnub.getConfiguration().isIncludeInstanceIdentifier()) { - params.put("instanceId", pubnub.getInstanceId()); + params.put("instanceid", pubnub.getInstanceId()); } if (this.pubnub.getConfiguration().isIncludeRequestIdentifier()) { - params.put("requestId", pubnub.getRequestId()); + params.put("requestid", pubnub.getRequestId()); } // add the auth key for publish and subscribe. diff --git a/src/test/java/com/pubnub/api/endpoints/EndpointTest.java b/src/test/java/com/pubnub/api/endpoints/EndpointTest.java index 334d802ad..503738578 100644 --- a/src/test/java/com/pubnub/api/endpoints/EndpointTest.java +++ b/src/test/java/com/pubnub/api/endpoints/EndpointTest.java @@ -25,7 +25,7 @@ public void beforeEach() throws IOException { } @Test - public void testUUID() throws PubNubException { + public void testBaseParams() throws PubNubException { Endpoint endpoint = new Endpoint(pubnub, null) { @Override @@ -90,6 +90,8 @@ public Request request() { }; Assert.assertEquals("myUUID",baseParams.get("uuid")); + Assert.assertEquals("PubNubRequestId",baseParams.get("requestid")); + Assert.assertEquals("PubNubInstanceId",baseParams.get("instanceid")); return fakeCall; } }; From 9fc25039ad1bc7f6df33b72d7c50082244c16e40 Mon Sep 17 00:00:00 2001 From: Marcelo Marques Inacio Date: Mon, 3 Oct 2016 22:17:44 -0300 Subject: [PATCH 4/7] Fixing Audit and Grant Unit Test --- .../endpoints/access/AuditEndpointTest.java | 18 +-- .../endpoints/access/GrantEndpointTest.java | 126 +++++++++--------- 2 files changed, 72 insertions(+), 72 deletions(-) diff --git a/src/test/java/com/pubnub/api/endpoints/access/AuditEndpointTest.java b/src/test/java/com/pubnub/api/endpoints/access/AuditEndpointTest.java index 62270f18f..c63673a4d 100644 --- a/src/test/java/com/pubnub/api/endpoints/access/AuditEndpointTest.java +++ b/src/test/java/com/pubnub/api/endpoints/access/AuditEndpointTest.java @@ -48,9 +48,9 @@ public void testSuccessChannelGroupSync() throws PubNubException { stubFor(get(urlPathEqualTo("/v1/auth/audit/sub-key/mySubscribeKey")) .withQueryParam("pnsdk", matching("PubNub-Java-Unified/suchJava")) - .withQueryParam("instanceId", matching("PubNubInstanceId")) - .withQueryParam("requestId", matching("PubNubRequestId")) - .withQueryParam("signature", matching("dVle3aE_grdzKypoEegdNSZs_CXpJQJEcnqcM0nMH0Q%3D%0A")) + .withQueryParam("instanceid", matching("PubNubInstanceId")) + .withQueryParam("requestid", matching("PubNubRequestId")) + .withQueryParam("signature", matching("rnb_-C8C4twE5IlyMeSlTyF4538WNv4uKCQu6jQwggU%3D%0A")) .withQueryParam("channel-group", matching("cg1")) .withQueryParam("auth", matching("key1")) .withQueryParam("uuid", matching("myUUID")) @@ -78,9 +78,9 @@ public void testSuccessChannelSync() throws PubNubException { .withQueryParam("pnsdk", matching("PubNub-Java-Unified/suchJava")) .withQueryParam("channel", matching("ch1")) .withQueryParam("auth", matching("key1")) - .withQueryParam("instanceId", matching("PubNubInstanceId")) - .withQueryParam("requestId", matching("PubNubRequestId")) - .withQueryParam("signature", matching("4WIVMIc007EqwYGrqyJuMy5qf-gvtdopDjfaXEa1zOs%3D%0A")) + .withQueryParam("instanceid", matching("PubNubInstanceId")) + .withQueryParam("requestid", matching("PubNubRequestId")) + .withQueryParam("signature", matching("l0mnete94wADUcKR6THq1L4nhJrJg5q7eot0uRWoT8U%3D%0A")) .withQueryParam("uuid", matching("myUUID")) .withQueryParam("timestamp", matching("1337")) .willReturn(aResponse().withBody("{\"message\":\"Success\",\"payload\":{\"level\":\"user\",\"subscribe_key\":\"sub-c-82ab2196-b64f-11e5-8622-0619f8945a4f\",\"channel\":\"ch1\",\"auths\":{\"key1\":{\"r\":1,\"m\":1,\"w\":1}}},\"service\":\"Access Manager\",\"status\":200}"))); @@ -147,9 +147,9 @@ public void testIsAuthRequiredSuccessSync() throws IOException, PubNubException, .withQueryParam("pnsdk", matching("PubNub-Java-Unified/suchJava")) .withQueryParam("channel-group", matching("cg1")) .withQueryParam("auth", matching("key1")) - .withQueryParam("instanceId", matching("PubNubInstanceId")) - .withQueryParam("requestId", matching("PubNubRequestId")) - .withQueryParam("signature", matching("dVle3aE_grdzKypoEegdNSZs_CXpJQJEcnqcM0nMH0Q%3D%0A")) + .withQueryParam("instanceid", matching("PubNubInstanceId")) + .withQueryParam("requestid", matching("PubNubRequestId")) + .withQueryParam("signature", matching("rnb_-C8C4twE5IlyMeSlTyF4538WNv4uKCQu6jQwggU%3D%0A")) .withQueryParam("uuid", matching("myUUID")) .withQueryParam("timestamp", matching("1337")) .willReturn(aResponse().withBody("{\"message\":\"Success\",\"payload\":{\"level\":\"channel-group+auth\",\"subscribe_key\":\"sub-c-82ab2196-b64f-11e5-8622-0619f8945a4f\",\"channel-group\":\"cg2\",\"auths\":{\"key1\":{\"r\":1,\"m\":1,\"w\":1}}},\"service\":\"Access Manager\",\"status\":200}"))); diff --git a/src/test/java/com/pubnub/api/endpoints/access/GrantEndpointTest.java b/src/test/java/com/pubnub/api/endpoints/access/GrantEndpointTest.java index 125f2c70a..67e1f7935 100644 --- a/src/test/java/com/pubnub/api/endpoints/access/GrantEndpointTest.java +++ b/src/test/java/com/pubnub/api/endpoints/access/GrantEndpointTest.java @@ -47,9 +47,9 @@ public void NoGroupsOneChannelOneKeyTest() throws PubNubException { .withQueryParam("pnsdk", matching("PubNub-Java-Unified/suchJava")) .withQueryParam("channel", matching("ch1")) .withQueryParam("auth", matching("key1")) - .withQueryParam("instanceId", matching("PubNubInstanceId")) - .withQueryParam("requestId", matching("PubNubRequestId")) - .withQueryParam("signature", matching("Sw4LDrBsxjXYgzw6H2ww_omDFmT5Sozd2Bd0NDRQ7GA%3D%0A")) + .withQueryParam("instanceid", matching("PubNubInstanceId")) + .withQueryParam("requestid", matching("PubNubRequestId")) + .withQueryParam("signature", matching("nUZe6LEDe2RGPeh4qoe-IpjAYzBf8RJMtSXI7ktaah8%3D%0A")) .withQueryParam("uuid", matching("myUUID")) .withQueryParam("timestamp", matching("1337")) .withQueryParam("r", matching("0")) @@ -74,9 +74,9 @@ public void NoGroupsOneChannelTwoKeyTest() throws PubNubException { .withQueryParam("pnsdk", matching("PubNub-Java-Unified/suchJava")) .withQueryParam("channel", matching("ch1")) .withQueryParam("auth", matching("key1,key2")) - .withQueryParam("instanceId", matching("PubNubInstanceId")) - .withQueryParam("requestId", matching("PubNubRequestId")) - .withQueryParam("signature", matching("LY9uFbCRnA1fHZLd2kBsIdM9LocwnVTIHxwp3BwQ5XQ%3D%0A")) + .withQueryParam("instanceid", matching("PubNubInstanceId")) + .withQueryParam("requestid", matching("PubNubRequestId")) + .withQueryParam("signature", matching("ml__GSdczD-5CLqz8Vappaux1bZj6IycOP4O6FyS7ek%3D%0A")) .withQueryParam("uuid", matching("myUUID")) .withQueryParam("timestamp", matching("1337")) .withQueryParam("r", matching("0")) @@ -101,9 +101,9 @@ public void NoGroupsTwoChannelOneKeyTest() throws PubNubException { .withQueryParam("pnsdk", matching("PubNub-Java-Unified/suchJava")) .withQueryParam("channel", matching("ch1,ch2")) .withQueryParam("auth", matching("key1")) - .withQueryParam("instanceId", matching("PubNubInstanceId")) - .withQueryParam("requestId", matching("PubNubRequestId")) - .withQueryParam("signature", matching("_z51OsbDp9kvYfKQZUJoiyo82_QuAVZ7JyKi9zoGFAc%3D%0A")) + .withQueryParam("instanceid", matching("PubNubInstanceId")) + .withQueryParam("requestid", matching("PubNubRequestId")) + .withQueryParam("signature", matching("J6g30_aZUtbXOLCQ3kkYx0-K6Rm0F-pFUPa3kZ2647Q%3D%0A")) .withQueryParam("uuid", matching("myUUID")) .withQueryParam("timestamp", matching("1337")) .withQueryParam("r", matching("0")) @@ -129,9 +129,9 @@ public void NoGroupsTwoChannelTwoKeyTest() throws PubNubException { .withQueryParam("pnsdk", matching("PubNub-Java-Unified/suchJava")) .withQueryParam("channel", matching("ch1,ch2")) .withQueryParam("auth", matching("key1,key2")) - .withQueryParam("instanceId", matching("PubNubInstanceId")) - .withQueryParam("requestId", matching("PubNubRequestId")) - .withQueryParam("signature", matching("_TV8Gcpvr6L1W-9cARyGXMj3x3VIJwP1_Cuz3oDDHRE%3D%0A")) + .withQueryParam("instanceid", matching("PubNubInstanceId")) + .withQueryParam("requestid", matching("PubNubRequestId")) + .withQueryParam("signature", matching("-3DlrA39lnyhbjTtuJC6s13Gc5Owa_SdRxAx3zJFUd4%3D%0A")) .withQueryParam("uuid", matching("myUUID")) .withQueryParam("timestamp", matching("1337")) .withQueryParam("r", matching("0")) @@ -159,9 +159,9 @@ public void OneGroupNoChannelOneKey() throws PubNubException { .withQueryParam("pnsdk", matching("PubNub-Java-Unified/suchJava")) .withQueryParam("channel-group", matching("cg1")) .withQueryParam("auth", matching("key1")) - .withQueryParam("instanceId", matching("PubNubInstanceId")) - .withQueryParam("requestId", matching("PubNubRequestId")) - .withQueryParam("signature", matching("JsJT8pcHUKP3OBpkuNznbmxRejYC_DQBZldbpphM1sk%3D%0A")) + .withQueryParam("instanceid", matching("PubNubInstanceId")) + .withQueryParam("requestid", matching("PubNubRequestId")) + .withQueryParam("signature", matching("JfuIHr4BMGVbaAVp1QdDvvhcX2aaCEqINIcIsHJMGCs%3D%0A")) .withQueryParam("uuid", matching("myUUID")) .withQueryParam("timestamp", matching("1337")) .withQueryParam("r", matching("0")) @@ -186,9 +186,9 @@ public void OneGroupNoChannelTwoKey() throws PubNubException { .withQueryParam("pnsdk", matching("PubNub-Java-Unified/suchJava")) .withQueryParam("channel-group", matching("cg1")) .withQueryParam("auth", matching("key1,key2")) - .withQueryParam("instanceId", matching("PubNubInstanceId")) - .withQueryParam("requestId", matching("PubNubRequestId")) - .withQueryParam("signature", matching("BlTyZ9ysUV8JEU1BMps8Kfjqbu3m0dsUDRHlbnNIX5Y%3D%0A")) + .withQueryParam("instanceid", matching("PubNubInstanceId")) + .withQueryParam("requestid", matching("PubNubRequestId")) + .withQueryParam("signature", matching("m47WC6N_zx9EhnX3XcO-bNS0wO5Fw4sj8154NoyyVKs%3D%0A")) .withQueryParam("uuid", matching("myUUID")) .withQueryParam("timestamp", matching("1337")) .withQueryParam("r", matching("0")) @@ -215,9 +215,9 @@ public void OneGroupOneChannelOneKey() throws PubNubException { .withQueryParam("channel", matching("ch1")) .withQueryParam("channel-group", matching("cg1")) .withQueryParam("auth", matching("key1")) - .withQueryParam("instanceId", matching("PubNubInstanceId")) - .withQueryParam("requestId", matching("PubNubRequestId")) - .withQueryParam("signature", matching("CVKPMHlOKHpnjdM-yitToj3jC2Betd9QTyATN4GCgfU%3D%0A")) + .withQueryParam("instanceid", matching("PubNubInstanceId")) + .withQueryParam("requestid", matching("PubNubRequestId")) + .withQueryParam("signature", matching("TXuXp8mvpziVIeuyd8b0dgNXRYEJ9oBIhktnhilt7Xs%3D%0A")) .withQueryParam("uuid", matching("myUUID")) .withQueryParam("timestamp", matching("1337")) .withQueryParam("r", matching("0")) @@ -246,9 +246,9 @@ public void OneGroupOneChannelTwoKey() throws PubNubException { .withQueryParam("channel", matching("ch1")) .withQueryParam("channel-group", matching("cg1")) .withQueryParam("auth", matching("key1,key2")) - .withQueryParam("instanceId", matching("PubNubInstanceId")) - .withQueryParam("requestId", matching("PubNubRequestId")) - .withQueryParam("signature", matching("p21l4hlci0VGsQ_cDHfLubFALgtunt6ote7tBx4bpUU%3D%0A")) + .withQueryParam("instanceid", matching("PubNubInstanceId")) + .withQueryParam("requestid", matching("PubNubRequestId")) + .withQueryParam("signature", matching("KbQ7nkSPXZO_iTfn7nNfCO_Ut7OsEg4Hzb321vGgYUc%3D%0A")) .withQueryParam("uuid", matching("myUUID")) .withQueryParam("timestamp", matching("1337")) .withQueryParam("r", matching("0")) @@ -279,9 +279,9 @@ public void OneGroupTwoChannelOneKey() throws PubNubException { .withQueryParam("channel", matching("ch1,ch2")) .withQueryParam("channel-group", matching("cg1")) .withQueryParam("auth", matching("key1")) - .withQueryParam("instanceId", matching("PubNubInstanceId")) - .withQueryParam("requestId", matching("PubNubRequestId")) - .withQueryParam("signature", matching("ZEp63rTMmTh5N-uqN6UZuDP5GKE-b7SLwOrdi3yiBLM%3D%0A")) + .withQueryParam("instanceid", matching("PubNubInstanceId")) + .withQueryParam("requestid", matching("PubNubRequestId")) + .withQueryParam("signature", matching("gstN6_LP_z9LVMcBY4nAgXZQu_AcAta6Cuq2nWglbmw%3D%0A")) .withQueryParam("uuid", matching("myUUID")) .withQueryParam("timestamp", matching("1337")) .withQueryParam("r", matching("0")) @@ -311,9 +311,9 @@ public void OneGroupTwoChannelTwoKey() throws PubNubException { .withQueryParam("channel", matching("ch1,ch2")) .withQueryParam("channel-group", matching("cg1")) .withQueryParam("auth", matching("key1,key2")) - .withQueryParam("instanceId", matching("PubNubInstanceId")) - .withQueryParam("requestId", matching("PubNubRequestId")) - .withQueryParam("signature", matching("Kcl_Ba5CPDYXlhLcXyzhVHZlWTDaSRV5syEQjq5IGbU%3D%0A")) + .withQueryParam("instanceid", matching("PubNubInstanceId")) + .withQueryParam("requestid", matching("PubNubRequestId")) + .withQueryParam("signature", matching("p6eQF50jjcKvWQ1rulCE41WHKlJyp11byW989x4FEFc%3D%0A")) .withQueryParam("uuid", matching("myUUID")) .withQueryParam("timestamp", matching("1337")) .withQueryParam("r", matching("0")) @@ -346,9 +346,9 @@ public void TwoGroupNoChannelOneKey() throws PubNubException { .withQueryParam("pnsdk", matching("PubNub-Java-Unified/suchJava")) .withQueryParam("channel-group", matching("cg1,cg2")) .withQueryParam("auth", matching("key1")) - .withQueryParam("instanceId", matching("PubNubInstanceId")) - .withQueryParam("requestId", matching("PubNubRequestId")) - .withQueryParam("signature", matching("SLl749bJMEpxt_o7JeJdSTpLzTaq8P4aCC9jXWnDd58%3D%0A")) + .withQueryParam("instanceid", matching("PubNubInstanceId")) + .withQueryParam("requestid", matching("PubNubRequestId")) + .withQueryParam("signature", matching("rBRwhq15luvJ5IOFMgQqICHP_K10h0lm1m4TbKTgdWE%3D%0A")) .withQueryParam("uuid", matching("myUUID")) .withQueryParam("timestamp", matching("1337")) .withQueryParam("r", matching("0")) @@ -375,9 +375,9 @@ public void TwoGroupNoChannelTwoKey() throws PubNubException { .withQueryParam("pnsdk", matching("PubNub-Java-Unified/suchJava")) .withQueryParam("channel-group", matching("cg1,cg2")) .withQueryParam("auth", matching("key1,key2")) - .withQueryParam("instanceId", matching("PubNubInstanceId")) - .withQueryParam("requestId", matching("PubNubRequestId")) - .withQueryParam("signature", matching("Avb_BjSWm2KsdIXNDoU__q5zfKx7qKZbsEJ6Mo6y_BU%3D%0A")) + .withQueryParam("instanceid", matching("PubNubInstanceId")) + .withQueryParam("requestid", matching("PubNubRequestId")) + .withQueryParam("signature", matching("_78G4e79CvlnpKJfQTvORBGzimTFZfzxY5tcEVLW4Xs%3D%0A")) .withQueryParam("uuid", matching("myUUID")) .withQueryParam("timestamp", matching("1337")) .withQueryParam("r", matching("0")) @@ -406,9 +406,9 @@ public void TwoGroupOneChannelOneKey() throws PubNubException { .withQueryParam("channel", matching("ch1")) .withQueryParam("channel-group", matching("cg1,cg2")) .withQueryParam("auth", matching("key1")) - .withQueryParam("instanceId", matching("PubNubInstanceId")) - .withQueryParam("requestId", matching("PubNubRequestId")) - .withQueryParam("signature", matching("wa2h4HJ0b1pWS4R6oNtUKWB5BllrkPzc8GSK44GY2l8%3D%0A")) + .withQueryParam("instanceid", matching("PubNubInstanceId")) + .withQueryParam("requestid", matching("PubNubRequestId")) + .withQueryParam("signature", matching("8y9GXwhZFO1m9saIe1FVkAu5jIPMu-U9eHVSy0ybyio%3D%0A")) .withQueryParam("uuid", matching("myUUID")) .withQueryParam("timestamp", matching("1337")) .withQueryParam("r", matching("0")) @@ -438,9 +438,9 @@ public void TwoGroupOneChannelTwoKey() throws PubNubException { .withQueryParam("channel", matching("ch1")) .withQueryParam("channel-group", matching("cg1,cg2")) .withQueryParam("auth", matching("key1,key2")) - .withQueryParam("instanceId", matching("PubNubInstanceId")) - .withQueryParam("requestId", matching("PubNubRequestId")) - .withQueryParam("signature", matching("P3grHL6O8P185puxlqJZHFUz0_CoirZcaqFlHIhf7E0%3D%0A")) + .withQueryParam("instanceid", matching("PubNubInstanceId")) + .withQueryParam("requestid", matching("PubNubRequestId")) + .withQueryParam("signature", matching("GIgfQnwun0NgZNYD_rDtS3DkIuK7xMyWN8p_7kG4y5Q%3D%0A")) .withQueryParam("uuid", matching("myUUID")) .withQueryParam("timestamp", matching("1337")) .withQueryParam("r", matching("0")) @@ -473,9 +473,9 @@ public void TwoGroupTwoChannelOneKey() throws PubNubException { .withQueryParam("pnsdk", matching("PubNub-Java-Unified/suchJava")) .withQueryParam("channel", matching("ch1,ch2")) .withQueryParam("auth", matching("key1")) - .withQueryParam("instanceId", matching("PubNubInstanceId")) - .withQueryParam("requestId", matching("PubNubRequestId")) - .withQueryParam("signature", matching("UuOtPl3i-6nThXYsxuoMcMTo6RkLRriVYXQb9yH4UgY%3D%0A")) + .withQueryParam("instanceid", matching("PubNubInstanceId")) + .withQueryParam("requestid", matching("PubNubRequestId")) + .withQueryParam("signature", matching("Kvm2uRwgJ60iGYyvI60KC_WIdU3cxIKyYaX1LK0PL3c%3D%0A")) .withQueryParam("uuid", matching("myUUID")) .withQueryParam("timestamp", matching("1337")) .withQueryParam("r", matching("0")) @@ -507,9 +507,9 @@ public void TwoGroupTwoChannelTwoKey() throws PubNubException { .withQueryParam("channel", matching("ch1,ch2")) .withQueryParam("channel-group", matching("cg1,cg2")) .withQueryParam("auth", matching("key1,key2")) - .withQueryParam("instanceId", matching("PubNubInstanceId")) - .withQueryParam("requestId", matching("PubNubRequestId")) - .withQueryParam("signature", matching("yNi_IK2z0dH3MTwpQZNnUGsba5jyg9nI4PYwMP1WH74%3D%0A")) + .withQueryParam("instanceid", matching("PubNubInstanceId")) + .withQueryParam("requestid", matching("PubNubRequestId")) + .withQueryParam("signature", matching("uptOF3nuKzGHSJ-swKQFj4XSgzKetO5uHl9iRkPeYGY%3D%0A")) .withQueryParam("uuid", matching("myUUID")) .withQueryParam("timestamp", matching("1337")) .withQueryParam("r", matching("0")) @@ -545,9 +545,9 @@ public void NoGroupsOneChannelOneKeyTTLTest() throws PubNubException { .withQueryParam("pnsdk", matching("PubNub-Java-Unified/suchJava")) .withQueryParam("channel", matching("ch1")) .withQueryParam("auth", matching("key1")) - .withQueryParam("instanceId", matching("PubNubInstanceId")) - .withQueryParam("requestId", matching("PubNubRequestId")) - .withQueryParam("signature", matching("uzvZ_RvrHrU0alJGZ5CYhf2i0X5jfjwCXkr4BPFiKPE%3D%0A")) + .withQueryParam("instanceid", matching("PubNubInstanceId")) + .withQueryParam("requestid", matching("PubNubRequestId")) + .withQueryParam("signature", matching("VcJTCcpMugw4Stm409oUeaLWR0-ZewRJNKKetI6A1Jk%3D%0A")) .withQueryParam("uuid", matching("myUUID")) .withQueryParam("timestamp", matching("1337")) .withQueryParam("r", matching("0")) @@ -573,9 +573,9 @@ public void NoGroupsOneChannelOneReadKeyTest() throws PubNubException { .withQueryParam("pnsdk", matching("PubNub-Java-Unified/suchJava")) .withQueryParam("channel", matching("ch1")) .withQueryParam("auth", matching("key1")) - .withQueryParam("instanceId", matching("PubNubInstanceId")) - .withQueryParam("requestId", matching("PubNubRequestId")) - .withQueryParam("signature", matching("w-pT2ZJEAp85vvIZCdKwpNG3-QW4_q7wwPMIvh8KBIw%3D%0A")) + .withQueryParam("instanceid", matching("PubNubInstanceId")) + .withQueryParam("requestid", matching("PubNubRequestId")) + .withQueryParam("signature", matching("9ngAxIIhZUq6qqCAPXwcpoqPlSRXDokohXmgZ9jEZsM%3D%0A")) .withQueryParam("uuid", matching("myUUID")) .withQueryParam("timestamp", matching("1337")) .withQueryParam("r", matching("1")) @@ -600,9 +600,9 @@ public void NoGroupsOneChannelOneWriteKeyTest() throws PubNubException { .withQueryParam("pnsdk", matching("PubNub-Java-Unified/suchJava")) .withQueryParam("channel", matching("ch1")) .withQueryParam("auth", matching("key1")) - .withQueryParam("instanceId", matching("PubNubInstanceId")) - .withQueryParam("requestId", matching("PubNubRequestId")) - .withQueryParam("signature", matching("me6ZZegEWBqCmjs8dNb4BmB7Y-15FV8KXfecSxm2Y0o%3D%0A")) + .withQueryParam("instanceid", matching("PubNubInstanceId")) + .withQueryParam("requestid", matching("PubNubRequestId")) + .withQueryParam("signature", matching("ZNoFdFsoGjNmKLoOFPW7Xn9es3c41ZG1gHZ3Szz9BbA%3D%0A")) .withQueryParam("uuid", matching("myUUID")) .withQueryParam("timestamp", matching("1337")) .withQueryParam("r", matching("0")) @@ -627,9 +627,9 @@ public void NoGroupsOneChannelOneKeyManageTest() throws PubNubException { .withQueryParam("pnsdk", matching("PubNub-Java-Unified/suchJava")) .withQueryParam("channel", matching("ch1")) .withQueryParam("auth", matching("key1")) - .withQueryParam("instanceId", matching("PubNubInstanceId")) - .withQueryParam("requestId", matching("PubNubRequestId")) - .withQueryParam("signature", matching("VNOI32TCodRd3Uzw0_gRQjbsKVnl6fGkFkXDa08hrkU%3D%0A")) + .withQueryParam("instanceid", matching("PubNubInstanceId")) + .withQueryParam("requestid", matching("PubNubRequestId")) + .withQueryParam("signature", matching("lMTGADViQb_pQPkwOypoiRhiJGdN2prTlWlHCfZrgx0%3D%0A")) .withQueryParam("uuid", matching("myUUID")) .withQueryParam("timestamp", matching("1337")) .withQueryParam("r", matching("0")) @@ -673,9 +673,9 @@ public void testIsAuthRequiredSuccessSync() throws IOException, PubNubException, .withQueryParam("pnsdk", matching("PubNub-Java-Unified/suchJava")) .withQueryParam("channel", matching("ch1")) .withQueryParam("auth", matching("key1")) - .withQueryParam("instanceId", matching("PubNubInstanceId")) - .withQueryParam("requestId", matching("PubNubRequestId")) - .withQueryParam("signature", matching("Sw4LDrBsxjXYgzw6H2ww_omDFmT5Sozd2Bd0NDRQ7GA%3D%0A")) + .withQueryParam("instanceid", matching("PubNubInstanceId")) + .withQueryParam("requestid", matching("PubNubRequestId")) + .withQueryParam("signature", matching("nUZe6LEDe2RGPeh4qoe-IpjAYzBf8RJMtSXI7ktaah8%3D%0A")) .withQueryParam("uuid", matching("myUUID")) .withQueryParam("timestamp", matching("1337")) .withQueryParam("r", matching("0")) From a2632011cb6154548bf5b5d03e83c85f5087f8fc Mon Sep 17 00:00:00 2001 From: Max Presman Date: Tue, 11 Oct 2016 16:00:37 -0700 Subject: [PATCH 5/7] 4.1.0 --- .pubnub.yml | 11 ++++++++++- CHANGELOG.md | 18 ++++++++++++++++++ build.gradle | 2 +- .../java/com/pubnub/api/PNConfiguration.java | 4 +--- src/main/java/com/pubnub/api/PubNub.java | 11 ++++++++++- .../api/managers/SubscriptionManager.java | 6 ++++++ src/test/java/com/pubnub/api/PubNubTest.java | 2 +- .../com/pubnub/api/endpoints/EndpointTest.java | 1 + .../endpoints/access/AuditEndpointTest.java | 2 +- .../endpoints/access/GrantEndpointTest.java | 2 +- 10 files changed, 50 insertions(+), 9 deletions(-) diff --git a/.pubnub.yml b/.pubnub.yml index d4531d829..b2fb49c7d 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,8 +1,17 @@ name: java -version: 4.0.14 +version: 4.1.0 schema: 1 scm: github.com/pubnub/java changelog: + - version: v4.1.0 + date: + changes: + - type: improvement + text: destory now correctly forces the producer thread to shut down; stop is now deprecated for disconnect + - type: improvement + text: support for sending instance id for presence detection (disabled by default) + - type: improvement + text: support for sending request id to burst cache (enabled by default) - version: v4.0.14 date: changes: diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e11019c2..18efd91c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,22 @@ +## [v4.1.0](https://github.com/pubnub/java/tree/v4.1.0) + + + [Full Changelog](https://github.com/pubnub/java/compare/v4.0.14...v4.1.0) + + +- ⭐destory now correctly forces the producer thread to shut down; stop is now deprecated for disconnect + + + +- ⭐support for sending instance id for presence detection (disabled by default) + + + +- ⭐support for sending request id to burst cache (enabled by default) + + + ## [v4.0.14](https://github.com/pubnub/java/tree/v4.0.14) diff --git a/build.gradle b/build.gradle index 34ebe9abf..58e4610d8 100644 --- a/build.gradle +++ b/build.gradle @@ -10,7 +10,7 @@ plugins { id 'findbugs' } group = 'com.pubnub' -version = '4.0.14' +version = '4.1.0' description = """""" diff --git a/src/main/java/com/pubnub/api/PNConfiguration.java b/src/main/java/com/pubnub/api/PNConfiguration.java index a7b1c3bbe..c9c4378eb 100644 --- a/src/main/java/com/pubnub/api/PNConfiguration.java +++ b/src/main/java/com/pubnub/api/PNConfiguration.java @@ -26,14 +26,12 @@ public class PNConfiguration { * Set to true to send a UUID for PubNub instance */ @Getter - @Setter(AccessLevel.NONE) private boolean includeInstanceIdentifier; /** * Set to true to send a UUID on each request */ @Getter - @Setter(AccessLevel.NONE) private boolean includeRequestIdentifier; /** @@ -138,7 +136,7 @@ public PNConfiguration() { secure = true; - includeInstanceIdentifier = true; + includeInstanceIdentifier = false; includeRequestIdentifier = true; diff --git a/src/main/java/com/pubnub/api/PubNub.java b/src/main/java/com/pubnub/api/PubNub.java index 9a3ad33a6..2578a4fd0 100644 --- a/src/main/java/com/pubnub/api/PubNub.java +++ b/src/main/java/com/pubnub/api/PubNub.java @@ -56,7 +56,7 @@ public class PubNub { private static final int TIMESTAMP_DIVIDER = 1000; private static final int MAX_SEQUENCE = 65535; - private static final String SDK_VERSION = "4.0.14"; + private static final String SDK_VERSION = "4.1.0"; public PubNub(final PNConfiguration initialConfig) { this.configuration = initialConfig; @@ -256,6 +256,7 @@ public String getVersion() { /** * Stop the SDK and terminate all listeners. */ + @Deprecated public final void stop() { subscriptionManager.stop(); } @@ -265,6 +266,7 @@ public final void stop() { */ public final void destroy() { retrofitManager.destroy(); + subscriptionManager.destroy(); } /** @@ -274,6 +276,13 @@ public final void reconnect() { subscriptionManager.reconnect(); } + /** + * Perform a disconnect from the listeners + */ + public final void disconnect() { + subscriptionManager.disconnect(); + } + public final Publish fire() { return publish().shouldStore(false).replicate(false); } diff --git a/src/main/java/com/pubnub/api/managers/SubscriptionManager.java b/src/main/java/com/pubnub/api/managers/SubscriptionManager.java index 4aa5ae1b4..b76d654cf 100644 --- a/src/main/java/com/pubnub/api/managers/SubscriptionManager.java +++ b/src/main/java/com/pubnub/api/managers/SubscriptionManager.java @@ -114,9 +114,15 @@ public final synchronized void disconnect() { } + @Deprecated() public synchronized void stop() { + consumerThread.interrupt(); disconnect(); + } + + public synchronized void destroy() { consumerThread.interrupt(); + this.disconnect(); } public final synchronized void adaptStateBuilder(final StateOperation stateOperation) { diff --git a/src/test/java/com/pubnub/api/PubNubTest.java b/src/test/java/com/pubnub/api/PubNubTest.java index b60f465d4..6cf98aa07 100644 --- a/src/test/java/com/pubnub/api/PubNubTest.java +++ b/src/test/java/com/pubnub/api/PubNubTest.java @@ -91,7 +91,7 @@ public void getVersionAndTimeStamp() throws PubNubException { pubnub = new PubNub(pnConfiguration); String version = pubnub.getVersion(); int timeStamp = pubnub.getTimestamp(); - Assert.assertEquals("4.0.14", version); + Assert.assertEquals("4.1.0", version); Assert.assertTrue(timeStamp > 0); } diff --git a/src/test/java/com/pubnub/api/endpoints/EndpointTest.java b/src/test/java/com/pubnub/api/endpoints/EndpointTest.java index 503738578..3056ec2ea 100644 --- a/src/test/java/com/pubnub/api/endpoints/EndpointTest.java +++ b/src/test/java/com/pubnub/api/endpoints/EndpointTest.java @@ -22,6 +22,7 @@ public class EndpointTest extends TestHarness { @Before public void beforeEach() throws IOException { pubnub = this.createPubNubInstance(8080); + pubnub.getConfiguration().setIncludeInstanceIdentifier(true); } @Test diff --git a/src/test/java/com/pubnub/api/endpoints/access/AuditEndpointTest.java b/src/test/java/com/pubnub/api/endpoints/access/AuditEndpointTest.java index c63673a4d..38bbc5604 100644 --- a/src/test/java/com/pubnub/api/endpoints/access/AuditEndpointTest.java +++ b/src/test/java/com/pubnub/api/endpoints/access/AuditEndpointTest.java @@ -38,7 +38,7 @@ public void beforeEach() throws IOException { pubnub = this.createPubNubInstance(8080); partialAudit = pubnub.audit(); - pubnub.getConfiguration().setSecretKey("secretKey"); + pubnub.getConfiguration().setSecretKey("secretKey").setIncludeInstanceIdentifier(true); wireMockRule.start(); } diff --git a/src/test/java/com/pubnub/api/endpoints/access/GrantEndpointTest.java b/src/test/java/com/pubnub/api/endpoints/access/GrantEndpointTest.java index 67e1f7935..f2105b341 100644 --- a/src/test/java/com/pubnub/api/endpoints/access/GrantEndpointTest.java +++ b/src/test/java/com/pubnub/api/endpoints/access/GrantEndpointTest.java @@ -36,7 +36,7 @@ public class GrantEndpointTest extends TestHarness { public void beforeEach() throws IOException { pubnub = this.createPubNubInstance(8080); partialGrant = pubnub.grant(); - pubnub.getConfiguration().setSecretKey("secretKey"); + pubnub.getConfiguration().setSecretKey("secretKey").setIncludeInstanceIdentifier(true); wireMockRule.start(); } From c67833e788cd3306cc66abba4ab9340934244213 Mon Sep 17 00:00:00 2001 From: Marcelo Marques Inacio Date: Wed, 12 Oct 2016 09:28:46 -0300 Subject: [PATCH 6/7] Add validateParams on Async EndPoint --- .../com/pubnub/api/endpoints/Endpoint.java | 1 + .../endpoints/access/GrantEndpointTest.java | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/src/main/java/com/pubnub/api/endpoints/Endpoint.java b/src/main/java/com/pubnub/api/endpoints/Endpoint.java index 49bef5f17..e2f8bbefe 100644 --- a/src/main/java/com/pubnub/api/endpoints/Endpoint.java +++ b/src/main/java/com/pubnub/api/endpoints/Endpoint.java @@ -110,6 +110,7 @@ public final void async(final PNCallback callback) { cachedCallback = callback; try { + this.validateParams(); call = doWork(createBaseParams()); } catch (PubNubException pubnubException) { callback.onResponse(null, createStatusResponse(PNStatusCategory.PNBadRequestCategory, null, pubnubException, null, null)); diff --git a/src/test/java/com/pubnub/api/endpoints/access/GrantEndpointTest.java b/src/test/java/com/pubnub/api/endpoints/access/GrantEndpointTest.java index f2105b341..5907badfb 100644 --- a/src/test/java/com/pubnub/api/endpoints/access/GrantEndpointTest.java +++ b/src/test/java/com/pubnub/api/endpoints/access/GrantEndpointTest.java @@ -868,5 +868,35 @@ public void testNullPayload() throws IOException, PubNubException, InterruptedEx partialGrant.authKeys(Arrays.asList("key1")).channels(Arrays.asList("ch1")).sync(); } + + @Test + public void testNullAuthKeyAsync() throws PubNubException { + + final AtomicInteger atomic = new AtomicInteger(0); + + stubFor(get(urlPathEqualTo("/v1/auth/grant/sub-key/mySubscribeKey")) + .withQueryParam("pnsdk", matching("PubNub-Java-Unified/suchJava")) + .withQueryParam("channel", matching("ch1")) + .withQueryParam("signature", matching("HlyfXDFhdgNhKfBzGaouxh2T2SRimm4bVq_JVKLRPQI%3D%0A")) + .withQueryParam("uuid", matching("myUUID")) + .withQueryParam("timestamp", matching("1337")) + .withQueryParam("r", matching("0")) + .withQueryParam("w", matching("0")) + .withQueryParam("m", matching("0")) + .willReturn(aResponse().withBody("{\"message\":\"Success\",\"payload\":{\"level\":\"user\",\"subscribe_key\":\"sub-c-82ab2196-b64f-11e5-8622-0619f8945a4f\",\"ttl\":1,\"channel\":\"ch1\",\"auths\":{\"key1\":{\"r\":0,\"w\":0,\"m\":0}}},\"service\":\"Access Manager\",\"status\":200}"))); + + + partialGrant.channels(Arrays.asList("ch1")).async(new PNCallback() { + @Override + public void onResponse(PNAccessManagerGrantResult result, PNStatus status) { + if (status != null && status.getOperation()== PNOperationType.PNAccessManagerGrant && status.isError()) { + atomic.incrementAndGet(); + } + } + }); + + Awaitility.await().atMost(5, TimeUnit.SECONDS).untilAtomic(atomic, org.hamcrest.core.IsEqual.equalTo(1)); + } + } From 0bfcce862da282ebb398e734b96c1b0a2c04e553 Mon Sep 17 00:00:00 2001 From: Max Presman Date: Wed, 12 Oct 2016 11:40:33 -0700 Subject: [PATCH 7/7] update readme --- .pubnub.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.pubnub.yml b/.pubnub.yml index b2fb49c7d..c959163ed 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -12,6 +12,8 @@ changelog: text: support for sending instance id for presence detection (disabled by default) - type: improvement text: support for sending request id to burst cache (enabled by default) + - type: improvement + text: proxy support via the native proxy configurator class. - version: v4.0.14 date: changes: