Skip to content

Commit

Permalink
Merge pull request #24 from claucambra/bugfix/refix-dav-url
Browse files Browse the repository at this point in the history
Fix dav URL for cases where user ID does not match username
  • Loading branch information
claucambra authored Nov 7, 2024
2 parents f554f00 + eba9666 commit 6bc6961
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 18 deletions.
3 changes: 2 additions & 1 deletion Sources/NextcloudFileProviderKit/Utilities/Account.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public struct Account: Equatable {
self.password = password
ncKitAccount = user + " " + serverUrl
self.serverUrl = serverUrl
davFilesUrl = serverUrl + Self.webDavFilesUrlSuffix + user
davFilesUrl = serverUrl + Self.webDavFilesUrlSuffix + id
}

public init?(dictionary: Dictionary<String, String>) {
Expand All @@ -56,6 +56,7 @@ public struct Account: Equatable {
public func dictionary() -> Dictionary<String, String> {
return [
AccountDictUsernameKey: username,
AccountDictIdKey: id,
AccountDictPasswordKey: password,
AccountDictNcKitAccountKey: ncKitAccount,
AccountDictServerUrlKey: serverUrl,
Expand Down
4 changes: 3 additions & 1 deletion Tests/Interface/MockRemoteInterface.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public class MockRemoteInterface: RemoteInterface {
directory: true,
account: account.ncKitAccount,
username: account.username,
userId: account.id,
serverUrl: account.serverUrl
)
guard let parent = parentItem(path: remotePath) else {
Expand Down Expand Up @@ -185,6 +186,7 @@ public class MockRemoteInterface: RemoteInterface {
data: itemData,
account: account.ncKitAccount,
username: account.username,
userId: account.id,
serverUrl: account.serverUrl
)

Expand Down Expand Up @@ -363,7 +365,7 @@ public class MockRemoteInterface: RemoteInterface {
profile.address = account.serverUrl
profile.backend = "mock"
profile.displayName = account.ncKitAccount
profile.userId = account.username
profile.userId = account.id
return (account.ncKitAccount, profile, nil, .success)
}

Expand Down
6 changes: 5 additions & 1 deletion Tests/Interface/MockRemoteItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class MockRemoteItem: Equatable {
public var size: Int64 { Int64(data?.count ?? 0) }
public var account: String
public var username: String
public var userId: String
public var serverUrl: String
public var nkfile: NKFile {
let file = NKFile()
Expand All @@ -38,7 +39,7 @@ public class MockRemoteItem: Equatable {
file.serverUrl = parent?.remotePath ?? remotePath
file.account = account
file.user = username
file.userId = username
file.userId = userId
file.urlBase = serverUrl
file.lock = locked
file.lockOwner = lockOwner
Expand All @@ -62,6 +63,7 @@ public class MockRemoteItem: Equatable {
lhs.modificationDate == rhs.modificationDate &&
lhs.account == rhs.account &&
lhs.username == rhs.username &&
lhs.userId == rhs.userId &&
lhs.serverUrl == rhs.serverUrl
}

Expand All @@ -79,6 +81,7 @@ public class MockRemoteItem: Equatable {
lockTimeOut: Date? = nil,
account: String,
username: String,
userId: String,
serverUrl: String
) {
self.identifier = identifier
Expand All @@ -94,6 +97,7 @@ public class MockRemoteItem: Equatable {
self.lockTimeOut = lockTimeOut
self.account = account
self.username = username
self.userId = userId
self.serverUrl = serverUrl
}
}
20 changes: 20 additions & 0 deletions Tests/InterfaceTests/MockRemoteInterfaceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ final class MockRemoteInterfaceTests: XCTestCase {
directory: true,
account: Self.account.ncKitAccount,
username: Self.account.username,
userId: Self.account.id,
serverUrl: Self.account.serverUrl
)

Expand All @@ -38,6 +39,7 @@ final class MockRemoteInterfaceTests: XCTestCase {
directory: true,
account: Self.account.ncKitAccount,
username: Self.account.username,
userId: Self.account.id,
serverUrl: Self.account.serverUrl
)
let itemB = MockRemoteItem(
Expand All @@ -48,6 +50,7 @@ final class MockRemoteInterfaceTests: XCTestCase {
directory: true,
account: Self.account.ncKitAccount,
username: Self.account.username,
userId: Self.account.id,
serverUrl: Self.account.serverUrl
)
let itemA_B = MockRemoteItem(
Expand All @@ -58,6 +61,7 @@ final class MockRemoteInterfaceTests: XCTestCase {
directory: true,
account: Self.account.ncKitAccount,
username: Self.account.username,
userId: Self.account.id,
serverUrl: Self.account.serverUrl
)
let targetItem = MockRemoteItem(
Expand All @@ -67,6 +71,7 @@ final class MockRemoteInterfaceTests: XCTestCase {
remotePath: Self.account.davFilesUrl + "/a/b/target",
account: Self.account.ncKitAccount,
username: Self.account.username,
userId: Self.account.id,
serverUrl: Self.account.serverUrl
)

Expand Down Expand Up @@ -166,6 +171,7 @@ final class MockRemoteInterfaceTests: XCTestCase {
directory: true,
account: Self.account.ncKitAccount,
username: Self.account.username,
userId: Self.account.id,
serverUrl: Self.account.serverUrl
)
let itemB = MockRemoteItem(
Expand All @@ -175,6 +181,7 @@ final class MockRemoteInterfaceTests: XCTestCase {
directory: true,
account: Self.account.ncKitAccount,
username: Self.account.username,
userId: Self.account.id,
serverUrl: Self.account.serverUrl
)
let itemC = MockRemoteItem(
Expand All @@ -184,6 +191,7 @@ final class MockRemoteInterfaceTests: XCTestCase {
directory: true,
account: Self.account.ncKitAccount,
username: Self.account.username,
userId: Self.account.id,
serverUrl: Self.account.serverUrl
)
let targetItem = MockRemoteItem(
Expand All @@ -192,6 +200,7 @@ final class MockRemoteInterfaceTests: XCTestCase {
remotePath: Self.account.davFilesUrl + "/a/c/target",
account: Self.account.ncKitAccount,
username: Self.account.username,
userId: Self.account.id,
serverUrl: Self.account.serverUrl
)

Expand Down Expand Up @@ -246,6 +255,7 @@ final class MockRemoteInterfaceTests: XCTestCase {
directory: true,
account: Self.account.ncKitAccount,
username: Self.account.username,
userId: Self.account.id,
serverUrl: Self.account.serverUrl
)
let itemB = MockRemoteItem(
Expand All @@ -255,6 +265,7 @@ final class MockRemoteInterfaceTests: XCTestCase {
directory: true,
account: Self.account.ncKitAccount,
username: Self.account.username,
userId: Self.account.id,
serverUrl: Self.account.serverUrl
)
let itemC = MockRemoteItem(
Expand All @@ -264,6 +275,7 @@ final class MockRemoteInterfaceTests: XCTestCase {
directory: true,
account: Self.account.ncKitAccount,
username: Self.account.username,
userId: Self.account.id,
serverUrl: Self.account.serverUrl
)
let itemA_A = MockRemoteItem(
Expand All @@ -273,6 +285,7 @@ final class MockRemoteInterfaceTests: XCTestCase {
directory: true,
account: Self.account.ncKitAccount,
username: Self.account.username,
userId: Self.account.id,
serverUrl: Self.account.serverUrl
)
let itemA_B = MockRemoteItem(
Expand All @@ -282,6 +295,7 @@ final class MockRemoteInterfaceTests: XCTestCase {
directory: true,
account: Self.account.ncKitAccount,
username: Self.account.username,
userId: Self.account.id,
serverUrl: Self.account.serverUrl
)
let itemC_A = MockRemoteItem(
Expand All @@ -291,6 +305,7 @@ final class MockRemoteInterfaceTests: XCTestCase {
directory: true,
account: Self.account.ncKitAccount,
username: Self.account.username,
userId: Self.account.id,
serverUrl: Self.account.serverUrl
)
let itemC_A_A = MockRemoteItem(
Expand All @@ -300,6 +315,7 @@ final class MockRemoteInterfaceTests: XCTestCase {
directory: true,
account: Self.account.ncKitAccount,
username: Self.account.username,
userId: Self.account.id,
serverUrl: Self.account.serverUrl
)

Expand Down Expand Up @@ -383,6 +399,7 @@ final class MockRemoteInterfaceTests: XCTestCase {
directory: true,
account: Self.account.ncKitAccount,
username: Self.account.username,
userId: Self.account.id,
serverUrl: Self.account.serverUrl
)
let itemB = MockRemoteItem(
Expand All @@ -392,6 +409,7 @@ final class MockRemoteInterfaceTests: XCTestCase {
directory: true,
account: Self.account.ncKitAccount,
username: Self.account.username,
userId: Self.account.id,
serverUrl: Self.account.serverUrl
)
let itemA_C = MockRemoteItem(
Expand All @@ -401,6 +419,7 @@ final class MockRemoteInterfaceTests: XCTestCase {
directory: true,
account: Self.account.ncKitAccount,
username: Self.account.username,
userId: Self.account.id,
serverUrl: Self.account.serverUrl
)
let itemA_C_D = MockRemoteItem(
Expand All @@ -409,6 +428,7 @@ final class MockRemoteInterfaceTests: XCTestCase {
remotePath: Self.account.davFilesUrl + "/a/c/d",
account: Self.account.ncKitAccount,
username: Self.account.username,
userId: Self.account.id,
serverUrl: Self.account.serverUrl
)

Expand Down
4 changes: 4 additions & 0 deletions Tests/NextcloudFileProviderKitTests/AccountTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ final class AccountTests: XCTest {
let account = Account(user: user, id: userId, serverUrl: serverUrl, password: password)

XCTAssertEqual(account.username, user)
XCTAssertEqual(account.id, userId)
XCTAssertEqual(account.password, password)
XCTAssertEqual(account.ncKitAccount, "\(user) \(serverUrl)")
XCTAssertEqual(account.serverUrl, serverUrl)
Expand All @@ -27,6 +28,7 @@ final class AccountTests: XCTest {
func testInitializationFromDictionary() {
let dictionary: [String: String] = [
AccountDictUsernameKey: "user",
AccountDictIdKey: "userId",
AccountDictPasswordKey: "password",
AccountDictNcKitAccountKey: "user https://example.com",
AccountDictServerUrlKey: "https://example.com",
Expand All @@ -37,6 +39,7 @@ final class AccountTests: XCTest {

XCTAssertNotNil(account)
XCTAssertEqual(account?.username, "user")
XCTAssertEqual(account?.id, "userId")
XCTAssertEqual(account?.password, "password")
XCTAssertEqual(account?.ncKitAccount, "user https://example.com")
XCTAssertEqual(account?.serverUrl, "https://example.com")
Expand All @@ -61,6 +64,7 @@ final class AccountTests: XCTest {

XCTAssertEqual(dictionary[AccountDictUsernameKey], "user")
XCTAssertEqual(dictionary[AccountDictPasswordKey], "password")
XCTAssertEqual(dictionary[AccountDictIdKey], "userId")
XCTAssertEqual(dictionary[AccountDictNcKitAccountKey], "user https://example.com")
XCTAssertEqual(dictionary[AccountDictServerUrlKey], "https://example.com")
XCTAssertEqual(dictionary[AccountDictDavFilesUrlKey], "https://example.com/remote.php/dav/files/user")
Expand Down
Loading

0 comments on commit 6bc6961

Please sign in to comment.