From 24af7d54c79ad4d311689343c878b3c5cda0edca Mon Sep 17 00:00:00 2001 From: "marcin.cebo" Date: Mon, 14 Oct 2024 21:42:35 +0200 Subject: [PATCH 1/5] AccessManager is based on PAM V3 token instead of PAM V2 authKey. We encourage new customers to use PAM V3 instead of V2. PAM V3 has pubnub.setToken(token) method to update token whereas in V2 to update authKey it was required to instancionate PubNub with new authKey --- .../chat/internal/utils/AccessManager.kt | 6 +- .../pubnub/integration/AccessManagerTest.kt | 111 ++++++++++++++++++ .../integration/BaseChatIntegrationTest.kt | 17 ++- .../integration/ChannelIntegrationTest.kt | 18 +-- .../integration/MembershipIntegrationTest.kt | 6 +- .../pubnub/integration/UserIntegrationTest.kt | 34 +++--- pubnub-kotlin | 2 +- 7 files changed, 155 insertions(+), 39 deletions(-) create mode 100644 pubnub-chat-impl/src/commonTest/kotlin/com/pubnub/integration/AccessManagerTest.kt diff --git a/pubnub-chat-impl/src/commonMain/kotlin/com/pubnub/chat/internal/utils/AccessManager.kt b/pubnub-chat-impl/src/commonMain/kotlin/com/pubnub/chat/internal/utils/AccessManager.kt index 40454516..36b5dedc 100644 --- a/pubnub-chat-impl/src/commonMain/kotlin/com/pubnub/chat/internal/utils/AccessManager.kt +++ b/pubnub-chat-impl/src/commonMain/kotlin/com/pubnub/chat/internal/utils/AccessManager.kt @@ -9,11 +9,11 @@ internal class AccessManager(private val chat: Chat) { internal enum class Permission { READ, WRITE, MANAGE, DELETE, GET, JOIN, UPDATE } fun canI(permission: Permission, resourceType: ResourceType, resourceName: String): Boolean { - val authKey = chat.pubNub.configuration.authKey - if (authKey.isEmpty()) { + val token: String? = chat.pubNub.getToken() + if (token.isNullOrEmpty()) { return true } - val parsedToken = chat.pubNub.parseToken(authKey) + val parsedToken = chat.pubNub.parseToken(token) return Companion.canI(resourceType, parsedToken, resourceName, permission) } diff --git a/pubnub-chat-impl/src/commonTest/kotlin/com/pubnub/integration/AccessManagerTest.kt b/pubnub-chat-impl/src/commonTest/kotlin/com/pubnub/integration/AccessManagerTest.kt new file mode 100644 index 00000000..e433ff13 --- /dev/null +++ b/pubnub-chat-impl/src/commonTest/kotlin/com/pubnub/integration/AccessManagerTest.kt @@ -0,0 +1,111 @@ +package com.pubnub.integration + +import com.pubnub.api.models.consumer.access_manager.v3.ChannelGrant +import com.pubnub.api.models.consumer.access_manager.v3.UUIDGrant +import com.pubnub.api.v2.callbacks.Result +import com.pubnub.chat.Channel +import com.pubnub.chat.Event +import com.pubnub.chat.internal.message.MessageImpl +import com.pubnub.chat.listenForEvents +import com.pubnub.chat.types.EventContent +import com.pubnub.test.await +import kotlinx.coroutines.test.runTest +import kotlin.test.Test +import kotlin.test.assertEquals + +class AccessManagerTest : BaseChatIntegrationTest() { + @Test + fun pubNubClient_with_PAM_enabled_should_not_getChannel_when_no_token_set() = runTest { + val channelId = channelPam.id + var statusCode = 0 + val expectedStatusCode = 403 // Forbidden, no valid security Token provided + chatPamClient.getChannel(channelId).async { result: Result -> + result.onFailure { e -> + statusCode = e.statusCode + }.onSuccess { channel: Channel? -> + throw IllegalStateException("Should not enter here. Should return exeption") + } + } + delayInMillis(1000) + assertEquals(expectedStatusCode, statusCode) + } + + @Test + fun pubNubClient_with_PAM_enabled_should_getChannel_when_token_set() = runTest { + // getToken from server + val channelId = channelPam.id + chatPamServer.createChannel(id = channelId).await() + val token = chatPamServer.pubNub.grantToken( + ttl = 1, + channels = listOf(ChannelGrant.name(get = true, name = channelId, read = true, write = true, manage = true)) // get = true + ).await().token + // client uses token generated by server + chatPamClient.pubNub.setToken(token) + + var actualChannelId: String? = "" + val token1 = chatPamClient.pubNub.getToken() + assertEquals(token1, token) + chatPamClient.getChannel(channelId).async { result: Result -> + result.onFailure { + throw IllegalStateException("Should not enter here. Should return channel.") + }.onSuccess { channel: Channel? -> + actualChannelId = channel?.id + } + } + delayInMillis(1000) + assertEquals(channelId, actualChannelId) + + chatPamServer.deleteChannel(id = channelId).await() + } + + @Test + fun setLastReadMessageTimetoken_should_send_Receipt_event_when_has_token() = runTest { + var numberOfReceiptEvents = 0 + val timetoken = 1000L + val channelId = channelPam.id + + // server generates token + val token = chatPamServer.pubNub.grantToken( + ttl = 1, + authorizedUUID = chatPamClient.currentUser.id, + channels = listOf( + ChannelGrant.name( + name = channelId, + read = true, + write = true, + get = true, + join = true, + update = true, + manage = true, + delete = true, + create = true + ) + ), + uuids = listOf(UUIDGrant.id(id = chatPamClient.currentUser.id, get = true, update = true, delete = true)) + ).await().token + + // client uses token retrieved from server + chatPamClient.pubNub.setToken(token) + + chatPamClient.listenForEvents(channelId) { event: Event -> + numberOfReceiptEvents++ + } + + val channel = chatPamClient.createChannel(channelId).await() + delayInMillis(1000) + val membership1 = channel.join().await().membership + membership1.setLastReadMessage( + MessageImpl( + chatPamClient, + timetoken, + EventContent.TextMessageContent("abc"), + channelId = channel.id, + userId = someUser.id + ) + ).await() + delayInMillis(1000) + assertEquals(2, numberOfReceiptEvents) // join and setLastReadMessage sets LastReadMessageTimetoken + + chatPamServer.deleteChannel(channelId).await() + } +} diff --git a/pubnub-chat-impl/src/commonTest/kotlin/com/pubnub/integration/BaseChatIntegrationTest.kt b/pubnub-chat-impl/src/commonTest/kotlin/com/pubnub/integration/BaseChatIntegrationTest.kt index 36e81dfb..af31cf02 100644 --- a/pubnub-chat-impl/src/commonTest/kotlin/com/pubnub/integration/BaseChatIntegrationTest.kt +++ b/pubnub-chat-impl/src/commonTest/kotlin/com/pubnub/integration/BaseChatIntegrationTest.kt @@ -27,7 +27,8 @@ internal const val THREAD_CHANNEL_ID_PREFIX = "threadChannel_id_" abstract class BaseChatIntegrationTest : BaseIntegrationTest() { lateinit var chat: ChatImpl lateinit var chat02: ChatImpl - lateinit var chatPam: ChatImpl + lateinit var chatPamServer: ChatImpl + lateinit var chatPamClient: ChatImpl lateinit var channel01: Channel // this simulates first user in channel01 lateinit var channel01Chat02: Channel // this simulates second user in channel01 lateinit var channel02: Channel @@ -35,7 +36,8 @@ abstract class BaseChatIntegrationTest : BaseIntegrationTest() { lateinit var channelPam: Channel lateinit var someUser: User lateinit var someUser02: User - lateinit var userPam: User + lateinit var userPamServer: User + lateinit var userPamClient: User var cleanup: MutableList Unit> = mutableListOf() // todo is this used? @BeforeTest @@ -43,7 +45,8 @@ abstract class BaseChatIntegrationTest : BaseIntegrationTest() { super.before() chat = ChatImpl(ChatConfiguration(), pubnub) chat02 = ChatImpl(ChatConfiguration(), pubnub02) - chatPam = ChatImpl(ChatConfiguration(), pubnubPam) + chatPamServer = ChatImpl(ChatConfiguration(), pubnubPamServer) + chatPamClient = ChatImpl(ChatConfiguration(), pubnubPamClient) val channel01Id = randomString() + "!_=-@" channel01 = ChannelImpl( chat = chat, @@ -96,7 +99,7 @@ abstract class BaseChatIntegrationTest : BaseIntegrationTest() { type = ChannelType.DIRECT, ) channelPam = ChannelImpl( - chat = chatPam, + chat = chatPamServer, id = randomString() + "!_=-@", name = randomString(), custom = mapOf(randomString() to randomString()), @@ -108,13 +111,15 @@ abstract class BaseChatIntegrationTest : BaseIntegrationTest() { // user has chat and chat has user they should be the same? someUser = chat.currentUser someUser02 = chat02.currentUser - userPam = chatPam.currentUser + userPamServer = chatPamServer.currentUser + userPamClient = chatPamClient.currentUser } @AfterTest fun afterTest() = runTest { pubnub.removeUUIDMetadata(someUser.id).await() - pubnub.removeUUIDMetadata(userPam.id).await() + pubnubPamServer.removeUUIDMetadata(userPamServer.id).await() + pubnubPamServer.removeUUIDMetadata(userPamClient.id).await() pubnub.removeChannelMetadata(channel01.id).await() pubnub.removeChannelMetadata(channel01Chat02.id).await() pubnub.removeChannelMetadata(channel02.id).await() diff --git a/pubnub-chat-impl/src/commonTest/kotlin/com/pubnub/integration/ChannelIntegrationTest.kt b/pubnub-chat-impl/src/commonTest/kotlin/com/pubnub/integration/ChannelIntegrationTest.kt index 7739a2a7..ff7ac763 100644 --- a/pubnub-chat-impl/src/commonTest/kotlin/com/pubnub/integration/ChannelIntegrationTest.kt +++ b/pubnub-chat-impl/src/commonTest/kotlin/com/pubnub/integration/ChannelIntegrationTest.kt @@ -198,7 +198,7 @@ class ChannelIntegrationTest : BaseChatIntegrationTest() { return@runTest } val userId = "userId" - val user = UserImpl(chat = chatPam, id = userId) + val user = UserImpl(chat = chatPamServer, id = userId) val ban = true val mute = true val reason = "rude" @@ -222,13 +222,13 @@ class ChannelIntegrationTest : BaseChatIntegrationTest() { var mute = true val reason = "rude" - channelPam.setRestrictions(user = userPam, mute = mute, reason = reason).await() - var restriction = channelPam.getUserRestrictions(userPam).await() + channelPam.setRestrictions(user = userPamServer, mute = mute, reason = reason).await() + var restriction = channelPam.getUserRestrictions(userPamServer).await() assertEquals(mute, restriction.mute) mute = false - channelPam.setRestrictions(user = userPam, mute = mute, reason = reason).await() - restriction = channelPam.getUserRestrictions(userPam).await() + channelPam.setRestrictions(user = userPamServer, mute = mute, reason = reason).await() + restriction = channelPam.getUserRestrictions(userPamServer).await() assertEquals(mute, restriction.mute) assertFalse(restriction.ban) assertNull(restriction.reason) @@ -236,9 +236,9 @@ class ChannelIntegrationTest : BaseChatIntegrationTest() { @Test fun canGetRestrictionForUserThatDoesNotHaveRestrictionSet() = runTest { - val restriction = channel01.getUserRestrictions(userPam).await() + val restriction = channel01.getUserRestrictions(userPamServer).await() assertEquals(channel01.id, restriction.channelId) - assertEquals(userPam.id, restriction.userId) + assertEquals(userPamServer.id, restriction.userId) assertFalse(restriction.mute) assertFalse(restriction.ban) assertNull(restriction.reason) @@ -261,14 +261,14 @@ class ChannelIntegrationTest : BaseChatIntegrationTest() { val channelId = channelPam.id channelPam.setRestrictions( - user = UserImpl(chat = chatPam, id = userId01), + user = UserImpl(chat = chatPamServer, id = userId01), ban = ban, mute = mute, reason = reason ) .await() channelPam.setRestrictions( - user = UserImpl(chat = chatPam, id = userId02), + user = UserImpl(chat = chatPamServer, id = userId02), ban = ban, mute = mute, reason = reason diff --git a/pubnub-chat-impl/src/commonTest/kotlin/com/pubnub/integration/MembershipIntegrationTest.kt b/pubnub-chat-impl/src/commonTest/kotlin/com/pubnub/integration/MembershipIntegrationTest.kt index 7e3c1227..d392278a 100644 --- a/pubnub-chat-impl/src/commonTest/kotlin/com/pubnub/integration/MembershipIntegrationTest.kt +++ b/pubnub-chat-impl/src/commonTest/kotlin/com/pubnub/integration/MembershipIntegrationTest.kt @@ -97,7 +97,7 @@ class MembershipIntegrationTest : BaseChatIntegrationTest() { @Test fun setLastReadMessage() = runTest { val timetoken = 1000L - chat.createChannel( + val channel = chat.createChannel( channel01.id, channel01.name, channel01.description, @@ -108,14 +108,14 @@ class MembershipIntegrationTest : BaseChatIntegrationTest() { channel01.status ).await() delayInMillis(1000) - val membership1 = channel01.join().await().membership + val membership1 = channel.join().await().membership val membershipUpdated = membership1.setLastReadMessage( MessageImpl( chat, timetoken, EventContent.TextMessageContent("abc"), - channelId = channel01.id, + channelId = channel.id, userId = someUser.id ) ).await() diff --git a/pubnub-chat-impl/src/commonTest/kotlin/com/pubnub/integration/UserIntegrationTest.kt b/pubnub-chat-impl/src/commonTest/kotlin/com/pubnub/integration/UserIntegrationTest.kt index 9d51dd7a..f72f20a0 100644 --- a/pubnub-chat-impl/src/commonTest/kotlin/com/pubnub/integration/UserIntegrationTest.kt +++ b/pubnub-chat-impl/src/commonTest/kotlin/com/pubnub/integration/UserIntegrationTest.kt @@ -29,15 +29,15 @@ class UserIntegrationTest : BaseChatIntegrationTest() { return@runTest } val channelId = "channelId01" - val channel = ChannelImpl(chat = chatPam, id = channelId) + val channel = ChannelImpl(chat = chatPamServer, id = channelId) val ban = true val mute = true val reason = "rude" - userPam.setRestrictions(channel = channel, ban = ban, mute = mute, reason = reason).await() + userPamServer.setRestrictions(channel = channel, ban = ban, mute = mute, reason = reason).await() - val restriction: Restriction = userPam.getChannelRestrictions(channel).await() - assertEquals(userPam.id, restriction.userId) + val restriction: Restriction = userPamServer.getChannelRestrictions(channel).await() + assertEquals(userPamServer.id, restriction.userId) assertEquals(channelId, restriction.channelId) assertEquals(ban, restriction.ban) assertEquals(mute, restriction.mute) @@ -59,20 +59,20 @@ class UserIntegrationTest : BaseChatIntegrationTest() { val page = null val sort: Collection> = listOf(PNSortKey.PNAsc(PNMembershipKey.CHANNEL_ID)) - userPam.setRestrictions( - channel = ChannelImpl(chat = chatPam, id = channelId01), + userPamServer.setRestrictions( + channel = ChannelImpl(chat = chatPamServer, id = channelId01), ban = ban, mute = mute, reason = reason ).await() - userPam.setRestrictions( - channel = ChannelImpl(chat = chatPam, id = channelId02), + userPamServer.setRestrictions( + channel = ChannelImpl(chat = chatPamServer, id = channelId02), ban = ban, mute = mute, reason = reason ).await() - val getRestrictionsResponse = userPam.getChannelsRestrictions(limit = limit, page = page, sort = sort).await() + val getRestrictionsResponse = userPamServer.getChannelsRestrictions(limit = limit, page = page, sort = sort).await() assertEquals(limit, getRestrictionsResponse.total) assertEquals(200, getRestrictionsResponse.status) @@ -103,21 +103,21 @@ class UserIntegrationTest : BaseChatIntegrationTest() { val page = null val sort: Collection> = listOf(PNSortKey.PNDesc(PNMembershipKey.CHANNEL_ID)) - userPam.setRestrictions( - channel = ChannelImpl(chat = chatPam, id = channelId01), + userPamServer.setRestrictions( + channel = ChannelImpl(chat = chatPamServer, id = channelId01), ban = ban, mute = mute, reason = reason ).await() - userPam.setRestrictions( - channel = ChannelImpl(chat = chatPam, id = channelId02), + userPamServer.setRestrictions( + channel = ChannelImpl(chat = chatPamServer, id = channelId02), ban = ban, mute = mute, reason = reason ).await() val getRestrictionsResponse: GetRestrictionsResponse = - userPam.getChannelsRestrictions(limit = limit, page = page, sort = sort).await() + userPamServer.getChannelsRestrictions(limit = limit, page = page, sort = sort).await() val firstRestriction = getRestrictionsResponse.restrictions.first() assertEquals(channelId02, firstRestriction.channelId) @@ -216,13 +216,13 @@ class UserIntegrationTest : BaseChatIntegrationTest() { val mute = true val ban = true val reason = "rude" - userPam.setRestrictions(channel = channelPam, mute = true, ban = true, reason = reason).await() - val restrictions = userPam.getChannelRestrictions(channel = channelPam).await() + userPamServer.setRestrictions(channel = channelPam, mute = true, ban = true, reason = reason).await() + val restrictions = userPamServer.getChannelRestrictions(channel = channelPam).await() assertEquals(mute, restrictions.mute) assertEquals(ban, restrictions.ban) assertEquals(reason, restrictions.reason) - val membershipsResponse: MembershipsResponse = userPam.getMemberships().await() + val membershipsResponse: MembershipsResponse = userPamServer.getMemberships().await() val internalModerationChannelCount = membershipsResponse.memberships.filter { membership -> membership.channel.id.contains(INTERNAL_MODERATION_PREFIX) }.size diff --git a/pubnub-kotlin b/pubnub-kotlin index e38ca914..b82cb999 160000 --- a/pubnub-kotlin +++ b/pubnub-kotlin @@ -1 +1 @@ -Subproject commit e38ca914595631e194ba23328a45d6dbe4fb5c36 +Subproject commit b82cb99928e18e5d252e432749d02bcb9b1673f5 From 722b7ad3c6e9e0acdf2e6ec06963b5ee9f3220ab Mon Sep 17 00:00:00 2001 From: "marcin.cebo" Date: Tue, 15 Oct 2024 14:57:26 +0200 Subject: [PATCH 2/5] AccessManager is based on PAM V3 token instead of PAM V2 authKey. We encourage new customers to use PAM V3 instead of V2. PAM V3 has pubnub.setToken(token) method to update token whereas in V2 to update authKey it was required to instancionate PubNub with new authKey --- .../kotlin/com/pubnub/integration/AccessManagerTest.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pubnub-chat-impl/src/commonTest/kotlin/com/pubnub/integration/AccessManagerTest.kt b/pubnub-chat-impl/src/commonTest/kotlin/com/pubnub/integration/AccessManagerTest.kt index e433ff13..c1041db6 100644 --- a/pubnub-chat-impl/src/commonTest/kotlin/com/pubnub/integration/AccessManagerTest.kt +++ b/pubnub-chat-impl/src/commonTest/kotlin/com/pubnub/integration/AccessManagerTest.kt @@ -5,6 +5,7 @@ import com.pubnub.api.models.consumer.access_manager.v3.UUIDGrant import com.pubnub.api.v2.callbacks.Result import com.pubnub.chat.Channel import com.pubnub.chat.Event +import com.pubnub.chat.Membership import com.pubnub.chat.internal.message.MessageImpl import com.pubnub.chat.listenForEvents import com.pubnub.chat.types.EventContent @@ -23,7 +24,7 @@ class AccessManagerTest : BaseChatIntegrationTest() { result.onFailure { e -> statusCode = e.statusCode }.onSuccess { channel: Channel? -> - throw IllegalStateException("Should not enter here. Should return exeption") + throw IllegalStateException("Should not enter here. Should return exception.") } } delayInMillis(1000) From 332d966e42d6c5221003e0ee2f8a2b1f41fa7b91 Mon Sep 17 00:00:00 2001 From: "marcin.cebo" Date: Tue, 15 Oct 2024 15:04:26 +0200 Subject: [PATCH 3/5] AccessManager is based on PAM V3 token instead of PAM V2 authKey. We encourage new customers to use PAM V3 instead of V2. PAM V3 has pubnub.setToken(token) method to update token whereas in V2 to update authKey it was required to instancionate PubNub with new authKey --- .../kotlin/com/pubnub/integration/AccessManagerTest.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/pubnub-chat-impl/src/commonTest/kotlin/com/pubnub/integration/AccessManagerTest.kt b/pubnub-chat-impl/src/commonTest/kotlin/com/pubnub/integration/AccessManagerTest.kt index c1041db6..5bcbafc9 100644 --- a/pubnub-chat-impl/src/commonTest/kotlin/com/pubnub/integration/AccessManagerTest.kt +++ b/pubnub-chat-impl/src/commonTest/kotlin/com/pubnub/integration/AccessManagerTest.kt @@ -5,7 +5,6 @@ import com.pubnub.api.models.consumer.access_manager.v3.UUIDGrant import com.pubnub.api.v2.callbacks.Result import com.pubnub.chat.Channel import com.pubnub.chat.Event -import com.pubnub.chat.Membership import com.pubnub.chat.internal.message.MessageImpl import com.pubnub.chat.listenForEvents import com.pubnub.chat.types.EventContent From 3aa133e85512b20ac0e0ae03b1b71876f1f6d791 Mon Sep 17 00:00:00 2001 From: "marcin.cebo" Date: Fri, 18 Oct 2024 13:23:51 +0200 Subject: [PATCH 4/5] Updated kotlin module --- pubnub-kotlin | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubnub-kotlin b/pubnub-kotlin index b82cb999..4525c1e2 160000 --- a/pubnub-kotlin +++ b/pubnub-kotlin @@ -1 +1 @@ -Subproject commit b82cb99928e18e5d252e432749d02bcb9b1673f5 +Subproject commit 4525c1e2761c45ecf4746619821f504381ba62e5 From 671407f32cf777b30246d01673b67f8d17c1b194 Mon Sep 17 00:00:00 2001 From: "marcin.cebo" Date: Fri, 18 Oct 2024 14:06:59 +0200 Subject: [PATCH 5/5] Changes after review --- pubnub-chat-api/pubnub_chat_api.podspec | 2 +- pubnub-chat-impl/pubnub_chat_impl.podspec | 2 +- .../pubnub/integration/AccessManagerTest.kt | 27 +++++-------------- pubnub_chat.podspec | 2 +- 4 files changed, 9 insertions(+), 24 deletions(-) diff --git a/pubnub-chat-api/pubnub_chat_api.podspec b/pubnub-chat-api/pubnub_chat_api.podspec index 2d1f2c55..4b4b951a 100644 --- a/pubnub-chat-api/pubnub_chat_api.podspec +++ b/pubnub-chat-api/pubnub_chat_api.podspec @@ -9,7 +9,7 @@ Pod::Spec.new do |spec| spec.vendored_frameworks = 'build/cocoapods/framework/pubnub_chat_api.framework' spec.libraries = 'c++' spec.ios.deployment_target = '14' - spec.dependency 'PubNubSwift', '8.0.0' + spec.dependency 'PubNubSwift', '8.0.1' if !Dir.exist?('build/cocoapods/framework/pubnub_chat_api.framework') || Dir.empty?('build/cocoapods/framework/pubnub_chat_api.framework') raise " diff --git a/pubnub-chat-impl/pubnub_chat_impl.podspec b/pubnub-chat-impl/pubnub_chat_impl.podspec index 660c6a17..37138142 100644 --- a/pubnub-chat-impl/pubnub_chat_impl.podspec +++ b/pubnub-chat-impl/pubnub_chat_impl.podspec @@ -9,7 +9,7 @@ Pod::Spec.new do |spec| spec.vendored_frameworks = 'build/cocoapods/framework/pubnub_chat_impl.framework' spec.libraries = 'c++' spec.ios.deployment_target = '14' - spec.dependency 'PubNubSwift', '8.0.0' + spec.dependency 'PubNubSwift', '8.0.1' if !Dir.exist?('build/cocoapods/framework/pubnub_chat_impl.framework') || Dir.empty?('build/cocoapods/framework/pubnub_chat_impl.framework') raise " diff --git a/pubnub-chat-impl/src/commonTest/kotlin/com/pubnub/integration/AccessManagerTest.kt b/pubnub-chat-impl/src/commonTest/kotlin/com/pubnub/integration/AccessManagerTest.kt index 5bcbafc9..f6b5224a 100644 --- a/pubnub-chat-impl/src/commonTest/kotlin/com/pubnub/integration/AccessManagerTest.kt +++ b/pubnub-chat-impl/src/commonTest/kotlin/com/pubnub/integration/AccessManagerTest.kt @@ -1,9 +1,8 @@ package com.pubnub.integration +import com.pubnub.api.PubNubException import com.pubnub.api.models.consumer.access_manager.v3.ChannelGrant import com.pubnub.api.models.consumer.access_manager.v3.UUIDGrant -import com.pubnub.api.v2.callbacks.Result -import com.pubnub.chat.Channel import com.pubnub.chat.Event import com.pubnub.chat.internal.message.MessageImpl import com.pubnub.chat.listenForEvents @@ -12,22 +11,16 @@ import com.pubnub.test.await import kotlinx.coroutines.test.runTest import kotlin.test.Test import kotlin.test.assertEquals +import kotlin.test.assertFailsWith class AccessManagerTest : BaseChatIntegrationTest() { @Test fun pubNubClient_with_PAM_enabled_should_not_getChannel_when_no_token_set() = runTest { val channelId = channelPam.id - var statusCode = 0 val expectedStatusCode = 403 // Forbidden, no valid security Token provided - chatPamClient.getChannel(channelId).async { result: Result -> - result.onFailure { e -> - statusCode = e.statusCode - }.onSuccess { channel: Channel? -> - throw IllegalStateException("Should not enter here. Should return exception.") - } - } - delayInMillis(1000) - assertEquals(expectedStatusCode, statusCode) + + val exception = assertFailsWith { chatPamClient.getChannel(channelId).await() } + assertEquals(expectedStatusCode, exception.statusCode) } @Test @@ -42,17 +35,9 @@ class AccessManagerTest : BaseChatIntegrationTest() { // client uses token generated by server chatPamClient.pubNub.setToken(token) - var actualChannelId: String? = "" val token1 = chatPamClient.pubNub.getToken() assertEquals(token1, token) - chatPamClient.getChannel(channelId).async { result: Result -> - result.onFailure { - throw IllegalStateException("Should not enter here. Should return channel.") - }.onSuccess { channel: Channel? -> - actualChannelId = channel?.id - } - } - delayInMillis(1000) + val actualChannelId = chatPamClient.getChannel(channelId).await()?.id assertEquals(channelId, actualChannelId) chatPamServer.deleteChannel(id = channelId).await() diff --git a/pubnub_chat.podspec b/pubnub_chat.podspec index d6ae55af..fe6f6aca 100644 --- a/pubnub_chat.podspec +++ b/pubnub_chat.podspec @@ -9,7 +9,7 @@ Pod::Spec.new do |spec| spec.vendored_frameworks = 'build/cocoapods/framework/PubNubChat.framework' spec.libraries = 'c++' spec.ios.deployment_target = '14' - spec.dependency 'PubNubSwift', '8.0.0' + spec.dependency 'PubNubSwift', '8.0.1' if !Dir.exist?('build/cocoapods/framework/PubNubChat.framework') || Dir.empty?('build/cocoapods/framework/PubNubChat.framework') raise "