Skip to content

Commit

Permalink
update visibility of PermissionPolicy fields
Browse files Browse the repository at this point in the history
  • Loading branch information
cameronvoell committed Jul 24, 2024
1 parent 700a16f commit c45536e
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 27 deletions.
18 changes: 9 additions & 9 deletions Sources/XMTPiOS/Mls/PermissionPolicySet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,16 @@ public enum GroupPermissionPreconfiguration {
}

public class PermissionPolicySet {
var addMemberPolicy: PermissionOption
var removeMemberPolicy: PermissionOption
var addAdminPolicy: PermissionOption
var removeAdminPolicy: PermissionOption
var updateGroupNamePolicy: PermissionOption
var updateGroupDescriptionPolicy: PermissionOption
var updateGroupImagePolicy: PermissionOption
var updateGroupPinnedFrameUrlPolicy: PermissionOption
public var addMemberPolicy: PermissionOption
public var removeMemberPolicy: PermissionOption
public var addAdminPolicy: PermissionOption
public var removeAdminPolicy: PermissionOption
public var updateGroupNamePolicy: PermissionOption
public var updateGroupDescriptionPolicy: PermissionOption
public var updateGroupImagePolicy: PermissionOption
public var updateGroupPinnedFrameUrlPolicy: PermissionOption

init(addMemberPolicy: PermissionOption, removeMemberPolicy: PermissionOption, addAdminPolicy: PermissionOption, removeAdminPolicy: PermissionOption, updateGroupNamePolicy: PermissionOption, updateGroupDescriptionPolicy: PermissionOption, updateGroupImagePolicy: PermissionOption, updateGroupPinnedFrameUrlPolicy: PermissionOption) {
public init(addMemberPolicy: PermissionOption, removeMemberPolicy: PermissionOption, addAdminPolicy: PermissionOption, removeAdminPolicy: PermissionOption, updateGroupNamePolicy: PermissionOption, updateGroupDescriptionPolicy: PermissionOption, updateGroupImagePolicy: PermissionOption, updateGroupPinnedFrameUrlPolicy: PermissionOption) {
self.addMemberPolicy = addMemberPolicy
self.removeMemberPolicy = removeMemberPolicy
self.addAdminPolicy = addAdminPolicy
Expand Down
58 changes: 40 additions & 18 deletions Tests/XMTPTests/GroupPermissionsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,46 @@

import CryptoKit
import XCTest
@testable import XMTPiOS
import XMTPiOS
import LibXMTP
import XMTPTestHelpers

@available(iOS 16, *)
class GroupPermissionTests: XCTestCase {
// Use these fixtures to talk to the local node
struct LocalFixtures {
var alice: PrivateKey!
var bob: PrivateKey!
var caro: PrivateKey!
var aliceClient: Client!
var bobClient: Client!
var caroClient: Client!
public var alice: PrivateKey!
public var bob: PrivateKey!
public var caro: PrivateKey!
public var aliceClient: Client!
public var bobClient: Client!
public var caroClient: Client!
}

enum CryptoError: Error {
case randomBytes, combinedPayload, hmacSignatureError
}

public func secureRandomBytes(count: Int) throws -> Data {
var bytes = [UInt8](repeating: 0, count: count)

// Fill bytes with secure random data
let status = SecRandomCopyBytes(
kSecRandomDefault,
count,
&bytes
)

// A status of errSecSuccess indicates success
if status == errSecSuccess {
return Data(bytes)
} else {
throw CryptoError.randomBytes
}
}

func localFixtures() async throws -> LocalFixtures {
let key = try Crypto.secureRandomBytes(count: 32)
let key = try secureRandomBytes(count: 32)
let alice = try PrivateKey.generate()
let aliceClient = try await Client.create(
account: alice,
Expand Down Expand Up @@ -68,7 +90,7 @@ class GroupPermissionTests: XCTestCase {

func testGroupCreatedWithCorrectAdminList() async throws {
let fixtures = try await localFixtures()
let bobGroup = try await fixtures.bobClient.conversations.newGroup(with: [fixtures.alice.walletAddress])
let bobGroup = try await fixtures.bobClient.conversations.newGroup(with: [fixtures.alice.address])
try await fixtures.aliceClient.conversations.sync()
let aliceGroup = try await fixtures.aliceClient.conversations.groups().first!

Expand All @@ -89,7 +111,7 @@ class GroupPermissionTests: XCTestCase {

func testGroupCanUpdateAdminList() async throws {
let fixtures = try await localFixtures()
let bobGroup = try await fixtures.bobClient.conversations.newGroup(with: [fixtures.alice.walletAddress, fixtures.caro.walletAddress], permissions: .adminOnly)
let bobGroup = try await fixtures.bobClient.conversations.newGroup(with: [fixtures.alice.address, fixtures.caro.address], permissions: .adminOnly)
try await fixtures.aliceClient.conversations.sync()
let aliceGroup = try await fixtures.aliceClient.conversations.groups().first!

Expand Down Expand Up @@ -156,7 +178,7 @@ class GroupPermissionTests: XCTestCase {

func testGroupCanUpdateSuperAdminList() async throws {
let fixtures = try await localFixtures()
let bobGroup = try await fixtures.bobClient.conversations.newGroup(with: [fixtures.alice.walletAddress, fixtures.caro.walletAddress], permissions: .adminOnly)
let bobGroup = try await fixtures.bobClient.conversations.newGroup(with: [fixtures.alice.address, fixtures.caro.address], permissions: .adminOnly)
try await fixtures.aliceClient.conversations.sync()
let aliceGroup = try await fixtures.aliceClient.conversations.groups().first!

Expand Down Expand Up @@ -186,7 +208,7 @@ class GroupPermissionTests: XCTestCase {

func testGroupMembersAndPermissionLevel() async throws {
let fixtures = try await localFixtures()
let bobGroup = try await fixtures.bobClient.conversations.newGroup(with: [fixtures.alice.walletAddress, fixtures.caro.walletAddress], permissions: .adminOnly)
let bobGroup = try await fixtures.bobClient.conversations.newGroup(with: [fixtures.alice.address, fixtures.caro.address], permissions: .adminOnly)
try await fixtures.aliceClient.conversations.sync()
let aliceGroup = try await fixtures.aliceClient.conversations.groups().first!

Expand Down Expand Up @@ -231,7 +253,7 @@ class GroupPermissionTests: XCTestCase {

func testCanCommitAfterInvalidPermissionsCommit() async throws {
let fixtures = try await localFixtures()
let bobGroup = try await fixtures.bobClient.conversations.newGroup(with: [fixtures.alice.walletAddress, fixtures.caro.walletAddress], permissions: .allMembers)
let bobGroup = try await fixtures.bobClient.conversations.newGroup(with: [fixtures.alice.address, fixtures.caro.address], permissions: .allMembers)
try await fixtures.aliceClient.conversations.sync()
let aliceGroup = try await fixtures.aliceClient.conversations.groups().first!

Expand All @@ -258,7 +280,7 @@ class GroupPermissionTests: XCTestCase {
func testCanUpdatePermissions() async throws {
let fixtures = try await localFixtures()
let bobGroup = try await fixtures.bobClient.conversations.newGroup(
with: [fixtures.alice.walletAddress, fixtures.caro.walletAddress],
with: [fixtures.alice.address, fixtures.caro.address],
permissions: .adminOnly
)
try await fixtures.aliceClient.conversations.sync()
Expand Down Expand Up @@ -291,7 +313,7 @@ class GroupPermissionTests: XCTestCase {
func testCanUpdatePinnedFrameUrl() async throws {
let fixtures = try await localFixtures()
let bobGroup = try await fixtures.bobClient.conversations.newGroup(
with: [fixtures.alice.walletAddress, fixtures.caro.walletAddress],
with: [fixtures.alice.address, fixtures.caro.address],
permissions: .adminOnly,
pinnedFrameUrl: "initial url"
)
Expand Down Expand Up @@ -334,8 +356,8 @@ class GroupPermissionTests: XCTestCase {
updateGroupImagePolicy: PermissionOption.admin,
updateGroupPinnedFrameUrlPolicy: PermissionOption.deny
)
let bobGroup = try await fixtures.bobClient.conversations.newGroupCustomPermissions(
with: [fixtures.alice.walletAddress, fixtures.caro.walletAddress],
let _bobGroup = try await fixtures.bobClient.conversations.newGroupCustomPermissions(
with: [fixtures.alice.address, fixtures.caro.address],
permissionPolicySet: permissionPolicySet,
pinnedFrameUrl: "initial url"
)
Expand Down Expand Up @@ -369,7 +391,7 @@ class GroupPermissionTests: XCTestCase {
)
await assertThrowsAsyncError(
try await fixtures.bobClient.conversations.newGroupCustomPermissions(
with: [fixtures.alice.walletAddress, fixtures.caro.walletAddress],
with: [fixtures.alice.address, fixtures.caro.address],
permissionPolicySet: permissionPolicySetInvalid,
pinnedFrameUrl: "initial url"
)
Expand Down

0 comments on commit c45536e

Please sign in to comment.