1515import io .ably .pubsub .internal .Side ;
1616import java .net .InetSocketAddress ;
1717import java .nio .charset .StandardCharsets ;
18+ import java .util .Arrays ;
1819import java .util .HashMap ;
20+ import java .util .List ;
1921import java .util .Map ;
2022import java .util .concurrent .atomic .AtomicReference ;
2123import org .junit .Test ;
2426 * The agent entries asserted here are what the platform reads to classify traffic (and, on
2527 * MAU-priced accounts, what earns the server exemption), so these tests are deliberately
2628 * strict: if one fails, billing classification is broken, not just a header.
29+ * <p>
30+ * The side entry is a versionless flag — a bare token on the wire, per ably/ably-common#361
31+ * — so the assertions also fail if a version (or any {@code /suffix}) reappears on it.
2732 */
2833public class PubSubServerTest {
2934
@@ -36,32 +41,40 @@ private static ClientOptions offlineOptions(String key) throws AblyException {
3641 return options ;
3742 }
3843
44+ /** The stamped entry is present as a versionless flag, and the other side's is absent. */
45+ private static void assertServerFlag (Map <String , String > agents ) {
46+ assertTrue ("expected the server side flag" , agents .containsKey (Side .SERVER_AGENT_IDENTIFIER ));
47+ assertNull ("the side flag is versionless" , agents .get (Side .SERVER_AGENT_IDENTIFIER ));
48+ assertFalse ("a server client must not carry the device entry" ,
49+ agents .containsKey (Side .DEVICE_AGENT_IDENTIFIER ));
50+ }
51+
3952 @ Test
4053 public void httpClient_stampsServerAgent () throws AblyException {
4154 AblyRest client = PubSubServer .httpClientBuilder (offlineOptions (FAKE_KEY )).build ();
42- assertEquals ( BuildConfig . VERSION , client .options .agents . get ( Side . SERVER_AGENT_IDENTIFIER ) );
55+ assertServerFlag ( client .options .agents );
4356 }
4457
4558 @ Test
4659 public void realtimeClient_stampsServerAgent () throws AblyException {
4760 AblyRealtime client = PubSubServer .realtimeClientBuilder (offlineOptions (FAKE_KEY )).build ();
48- assertEquals ( BuildConfig . VERSION , client .options .agents . get ( Side . SERVER_AGENT_IDENTIFIER ) );
61+ assertServerFlag ( client .options .agents );
4962 }
5063
5164 @ Test
5265 public void keyString_isAcceptedAndDisambiguatedAsKey () throws AblyException {
5366 AblyRest client = PubSubServer .httpClientBuilder (FAKE_KEY ).build ();
5467 assertEquals (FAKE_KEY , client .options .key );
5568 assertNull (client .options .token );
56- assertEquals ( BuildConfig . VERSION , client .options .agents . get ( Side . SERVER_AGENT_IDENTIFIER ) );
69+ assertServerFlag ( client .options .agents );
5770 }
5871
5972 @ Test
6073 public void tokenString_isAcceptedAndDisambiguatedAsToken () throws AblyException {
6174 AblyRest client = PubSubServer .httpClientBuilder (FAKE_TOKEN ).build ();
6275 assertEquals (FAKE_TOKEN , client .options .token );
6376 assertNull (client .options .key );
64- assertEquals ( BuildConfig . VERSION , client .options .agents . get ( Side . SERVER_AGENT_IDENTIFIER ) );
77+ assertServerFlag ( client .options .agents );
6578 }
6679
6780 @ Test
@@ -71,16 +84,17 @@ public void callerAgentEntries_arePreserved() throws AblyException {
7184 options .agents .put ("some-sdk" , "1.2.3" );
7285 AblyRest client = PubSubServer .httpClientBuilder (options ).build ();
7386 assertEquals ("1.2.3" , client .options .agents .get ("some-sdk" ));
74- assertEquals ( BuildConfig . VERSION , client .options .agents . get ( Side . SERVER_AGENT_IDENTIFIER ) );
87+ assertServerFlag ( client .options .agents );
7588 }
7689
7790 @ Test
7891 public void callerCannotOverrideTheSideEntry () throws AblyException {
7992 ClientOptions options = offlineOptions (FAKE_KEY );
8093 options .agents = new HashMap <>();
81- options .agents .put (Side .SERVER_AGENT_IDENTIFIER , "not-the-real-version " );
94+ options .agents .put (Side .SERVER_AGENT_IDENTIFIER , "not-the-real-form " );
8295 AblyRest client = PubSubServer .httpClientBuilder (options ).build ();
83- assertEquals (BuildConfig .VERSION , client .options .agents .get (Side .SERVER_AGENT_IDENTIFIER ));
96+ // The stamp replaces the caller's value: the flag is present and back to versionless.
97+ assertServerFlag (client .options .agents );
8498 }
8599
86100 @ Test
@@ -107,8 +121,8 @@ public void nullOptions_getTheCoreConstructorsOwnError() {
107121
108122 /**
109123 * Wire-level assertion: the Ably-Agent header actually sent over HTTP carries the
110- * side-declaring entry alongside the core's base identifier. This is the value billing
111- * classification reads.
124+ * side-declaring flag as a bare token alongside the core's base identifier. This is the
125+ * value billing classification reads.
112126 */
113127 @ Test
114128 public void httpRequests_carryTheServerAgentHeaderOnTheWire () throws Exception {
@@ -133,8 +147,13 @@ public void httpRequests_carryTheServerAgentHeaderOnTheWire() throws Exception {
133147
134148 String agentHeader = observedAgentHeader .get ();
135149 assertNotNull ("no Ably-Agent header observed" , agentHeader );
136- assertTrue ("missing side-declaring entry in: " + agentHeader ,
137- agentHeader .contains (Side .SERVER_AGENT_IDENTIFIER + "/" + BuildConfig .VERSION ));
150+ List <String > tokens = Arrays .asList (agentHeader .split (" " ));
151+ // The flag must be present as a bare token: `name/anything` means the
152+ // versionless stamp regressed (see ably/ably-common#361).
153+ assertTrue ("missing bare side flag in: " + agentHeader ,
154+ tokens .contains (Side .SERVER_AGENT_IDENTIFIER ));
155+ assertFalse ("side flag must be versionless in: " + agentHeader ,
156+ agentHeader .contains (Side .SERVER_AGENT_IDENTIFIER + "/" ));
138157 assertTrue ("missing core base identifier in: " + agentHeader ,
139158 agentHeader .contains ("ably-java/" ));
140159 } finally {
0 commit comments