From f7f19ccc84d26c167ddd826e0ab5a683b022c0d9 Mon Sep 17 00:00:00 2001 From: Umair Date: Thu, 14 Nov 2024 12:58:59 +0000 Subject: [PATCH] Removes reserved keyspaces in line with CHADR-066 - https://ably.atlassian.net/wiki/spaces/CHA/pages/3438116905/CHADR-066+Removing+Reserved+Keyspace --- Sources/AblyChat/ChatAPI.swift | 12 ------ Tests/AblyChatTests/ChatAPITests.swift | 59 -------------------------- 2 files changed, 71 deletions(-) diff --git a/Sources/AblyChat/ChatAPI.swift b/Sources/AblyChat/ChatAPI.swift index 947a4f1f..5142db50 100644 --- a/Sources/AblyChat/ChatAPI.swift +++ b/Sources/AblyChat/ChatAPI.swift @@ -32,22 +32,10 @@ internal final class ChatAPI: Sendable { // (CHA-M3b) A message may be sent without metadata or headers. When these are not specified by the user, they must be omitted from the REST payload. if let metadata = params.metadata { body["metadata"] = metadata - - // (CHA-M3c) metadata must not contain the key ably-chat. This is reserved for future internal use. If this key is present, the send call shall terminate by throwing an ErrorInfo with code 40001. - if metadata.contains(where: { $0.key == "ably-chat" }) { - throw ARTErrorInfo.create(withCode: 40001, message: "metadata must not contain the key `ably-chat`") - } } if let headers = params.headers { body["headers"] = headers - - // (CHA-M3d) headers must not contain a key prefixed with ably-chat. This is reserved for future internal use. If this key is present, the send call shall terminate by throwing an ErrorInfo with code 40001. - if headers.keys.contains(where: { keyString in - keyString.hasPrefix("ably-chat") - }) { - throw ARTErrorInfo.create(withCode: 40001, message: "headers must not contain any key with a prefix of `ably-chat`") - } } let response: SendMessageResponse = try await makeRequest(endpoint, method: "POST", body: body) diff --git a/Tests/AblyChatTests/ChatAPITests.swift b/Tests/AblyChatTests/ChatAPITests.swift index 53691da9..4c37d4df 100644 --- a/Tests/AblyChatTests/ChatAPITests.swift +++ b/Tests/AblyChatTests/ChatAPITests.swift @@ -5,65 +5,6 @@ import Testing struct ChatAPITests { // MARK: sendMessage Tests - // @spec CHA-M3c - @Test - func sendMessage_whenMetadataHasAblyChatAsKey_throws40001() async { - // Given - let realtime = MockRealtime.create() - let chatAPI = ChatAPI(realtime: realtime) - let roomId = "basketball::$chat::$chatMessages" - let expectedError = ARTErrorInfo.create(withCode: 40001, message: "metadata must not contain the key `ably-chat`") - - await #expect( - performing: { - // When - try await chatAPI.sendMessage(roomId: roomId, params: .init(text: "hello", metadata: ["ably-chat": .null])) - }, throws: { error in - // Then - error as? ARTErrorInfo == expectedError - } - ) - } - - // @specOneOf(1/2) CHA-M3d - @Test - func sendMessage_whenHeadersHasAnyKeyWithPrefixOfAblyChat_throws40001() async { - // Given - let realtime = MockRealtime.create { - (MockHTTPPaginatedResponse.successSendMessage, nil) - } - let chatAPI = ChatAPI(realtime: realtime) - let roomId = "basketball::$chat::$chatMessages" - let expectedError = ARTErrorInfo.create(withCode: 40001, message: "headers must not contain any key with a prefix of `ably-chat`") - - await #expect( - performing: { - // When - try await chatAPI.sendMessage(roomId: roomId, params: .init(text: "hello", headers: ["ably-chat123": .null])) - }, throws: { error in - // then - error as? ARTErrorInfo == expectedError - } - ) - } - - // @specOneOf(2/2) CHA-M3d - @Test - func sendMessage_whenHeadersHasAnyKeyWithSuffixOfAblyChat_doesNotThrowAnyError() async { - // Given - let realtime = MockRealtime.create { - (MockHTTPPaginatedResponse.successSendMessage, nil) - } - let chatAPI = ChatAPI(realtime: realtime) - let roomId = "basketball::$chat::$chatMessages" - - // Then - await #expect(throws: Never.self, performing: { - // When - try await chatAPI.sendMessage(roomId: roomId, params: .init(text: "hello", headers: ["123ably-chat": .null])) - }) - } - @Test func sendMessage_whenSendMessageReturnsNoItems_throwsNoItemInResponse() async { // Given