@@ -50,7 +50,7 @@ public static void tearDown() {
50
50
* should be included in all REST requests to the Ably endpoint
51
51
* see {@link io.ably.lib.transport.Defaults#ABLY_AGENT_PARAM}
52
52
* <p>
53
- * Spec: RSC7d, G4
53
+ * Spec: RSC7d, G4, RSA7e2
54
54
* </p>
55
55
*/
56
56
@ Test
@@ -83,12 +83,50 @@ public void header_lib_channel_publish() {
83
83
Assert .assertNotNull ("Expected headers" , headers );
84
84
Assert .assertEquals (headers .get ("x-ably-version" ), "2" );
85
85
Assert .assertEquals (headers .get ("ably-agent" ), expectedAblyAgentHeader );
86
+ // RSA7e2
87
+ Assert .assertNull ("Shouldn't include 'x-ably-clientid' if `clientId` is not specified" , headers .get ("x-ably-clientid" ));
86
88
} catch (AblyException e ) {
87
89
e .printStackTrace ();
88
90
Assert .fail ("header_lib_channel_publish: Unexpected exception" );
89
91
}
90
92
}
91
93
94
+ /**
95
+ * The header `X-Ably-ClientId`
96
+ * should be included in all REST requests to the Ably endpoint
97
+ * if {@link ClientOptions#clientId} is specified
98
+ * <p>
99
+ * Spec: RSA7e2
100
+ * </p>
101
+ */
102
+ @ Test
103
+ public void header_client_id_on_channel_publish () {
104
+ try {
105
+ /* Init values for local server */
106
+ ClientOptions opts = createOptions (testVars .keys [0 ].keyStr );
107
+ opts .environment = null ;
108
+ opts .tls = false ;
109
+ opts .port = server .getListeningPort ();
110
+ opts .restHost = "localhost" ;
111
+ opts .clientId = "test client" ;
112
+ AblyRest ably = new AblyRest (opts );
113
+
114
+ /* Publish message */
115
+ String messageName = "test message" ;
116
+ String messageData = String .valueOf (System .currentTimeMillis ());
117
+
118
+ Channel channel = ably .channels .get ("test" );
119
+ channel .publish (messageName , messageData );
120
+
121
+ /* Get last headers */
122
+ Map <String , String > headers = server .getHeaders ();
123
+ Assert .assertEquals (headers .get ("x-ably-clientid" ), /* Base64Coder.encodeString("test client") */ "dGVzdCBjbGllbnQ=" );
124
+ } catch (AblyException e ) {
125
+ e .printStackTrace ();
126
+ Assert .fail ("header_client_id_on_channel_publish: Unexpected exception" );
127
+ }
128
+ }
129
+
92
130
private static class SessionHandlerNanoHTTPD extends NanoHTTPD {
93
131
Map <String , String > requestHeaders ;
94
132
0 commit comments