Skip to content

Commit

Permalink
Added VaultFormatIntegrationsTests for box, improved README's and int…
Browse files Browse the repository at this point in the history
…egrate developer token.
  • Loading branch information
iammajid committed Apr 29, 2024
1 parent dab7df9 commit 995defc
Show file tree
Hide file tree
Showing 9 changed files with 301 additions and 11 deletions.
8 changes: 8 additions & 0 deletions CryptomatorCloudAccess.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@
9ED0E624246198F600FDB438 /* VaultFormat7CloudProviderMockTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9ED0E623246198F600FDB438 /* VaultFormat7CloudProviderMockTests.swift */; };
9EE62A0D247D54760089DAF7 /* CloudProvider+Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EE62A0C247D54760089DAF7 /* CloudProvider+Convenience.swift */; };
9EE62A10247D54E90089DAF7 /* CloudProvider+ConvenienceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EE62A0F247D54E90089DAF7 /* CloudProvider+ConvenienceTests.swift */; };
B322A2BB2BDF7F9F00306F01 /* VaultFormat7BoxIntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B322A2BA2BDF7F9F00306F01 /* VaultFormat7BoxIntegrationTests.swift */; };
B322A2BD2BDF7FBE00306F01 /* VaultFormat6BoxIntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B322A2BC2BDF7FBE00306F01 /* VaultFormat6BoxIntegrationTests.swift */; };
B3408AC82BCD32CA005271D2 /* BoxCredentialMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3408AC72BCD32CA005271D2 /* BoxCredentialMock.swift */; };
B3408ACA2BCDAA09005271D2 /* BoxError.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3408AC92BCDAA09005271D2 /* BoxError.swift */; };
B3D513912BA9A32200DE0D36 /* BoxAuthenticator.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3D5138D2BA9A32200DE0D36 /* BoxAuthenticator.swift */; };
Expand Down Expand Up @@ -384,6 +386,8 @@
9ED0E623246198F600FDB438 /* VaultFormat7CloudProviderMockTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VaultFormat7CloudProviderMockTests.swift; sourceTree = "<group>"; };
9EE62A0C247D54760089DAF7 /* CloudProvider+Convenience.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CloudProvider+Convenience.swift"; sourceTree = "<group>"; };
9EE62A0F247D54E90089DAF7 /* CloudProvider+ConvenienceTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CloudProvider+ConvenienceTests.swift"; sourceTree = "<group>"; };
B322A2BA2BDF7F9F00306F01 /* VaultFormat7BoxIntegrationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VaultFormat7BoxIntegrationTests.swift; sourceTree = "<group>"; };
B322A2BC2BDF7FBE00306F01 /* VaultFormat6BoxIntegrationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VaultFormat6BoxIntegrationTests.swift; sourceTree = "<group>"; };
B3408AC72BCD32CA005271D2 /* BoxCredentialMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BoxCredentialMock.swift; sourceTree = "<group>"; };
B3408AC92BCDAA09005271D2 /* BoxError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BoxError.swift; sourceTree = "<group>"; };
B3D5138D2BA9A32200DE0D36 /* BoxAuthenticator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BoxAuthenticator.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -653,6 +657,7 @@
4ACA63DA2615FF3B00D19304 /* VaultFormat6 */ = {
isa = PBXGroup;
children = (
B322A2BC2BDF7FBE00306F01 /* VaultFormat6BoxIntegrationTests.swift */,
4ACA63CB2615FF0000D19304 /* VaultFormat6DropboxIntegrationTests.swift */,
4ACA63D02615FF1600D19304 /* VaultFormat6GoogleDriveIntegrationTests.swift */,
4ACA63C62615FED700D19304 /* VaultFormat6LocalFileSystemIntegrationTests.swift */,
Expand All @@ -667,6 +672,7 @@
4ACA63E12615FF6400D19304 /* VaultFormat7 */ = {
isa = PBXGroup;
children = (
B322A2BA2BDF7F9F00306F01 /* VaultFormat7BoxIntegrationTests.swift */,
4ACA63E42615FF6400D19304 /* VaultFormat7DropboxIntegrationTests.swift */,
4ACA63E22615FF6400D19304 /* VaultFormat7GoogleDriveIntegrationTests.swift */,
4ACA63E52615FF6400D19304 /* VaultFormat7LocalFileSystemIntegrationTests.swift */,
Expand Down Expand Up @@ -1433,6 +1439,7 @@
7467A0D627DF9A8000BCFDF8 /* VaultFormat6PCloudIntegrationTests.swift in Sources */,
4AC75F9C2861A6DE002731FE /* VaultFormat6S3IntegrationTests.swift in Sources */,
4ACA63A02615FE2C00D19304 /* CloudAccessIntegrationTest.swift in Sources */,
B322A2BB2BDF7F9F00306F01 /* VaultFormat7BoxIntegrationTests.swift in Sources */,
B3D513972BA9A44000DE0D36 /* BoxCloudProviderIntegrationTests.swift in Sources */,
B3408AC82BCD32CA005271D2 /* BoxCredentialMock.swift in Sources */,
4ACA64262616054F00D19304 /* IntegrationTestSecrets.swift in Sources */,
Expand All @@ -1444,6 +1451,7 @@
4ACA63BB2615FEA600D19304 /* DecoratorFactory.swift in Sources */,
4ACA64042615FF9800D19304 /* GoogleDriveAuthenticatorMock.swift in Sources */,
4ACA64082615FF9800D19304 /* CloudProvider+CreateIntermediateFolderTests.swift in Sources */,
B322A2BD2BDF7FBE00306F01 /* VaultFormat6BoxIntegrationTests.swift in Sources */,
4ACA64022615FF9800D19304 /* DropboxCloudProviderIntegrationTests.swift in Sources */,
4ACA63D62615FF2E00D19304 /* VaultFormat6WebDAVIntegrationTests.swift in Sources */,
4AFC5F67263190BB00744715 /* OneDriveCloudProviderIntegrationTests.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1500"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "4ACA638D2615FDFF00D19304"
BuildableName = "CryptomatorCloudAccessIntegrationTests.xctest"
BlueprintName = "CryptomatorCloudAccessIntegrationTests"
ReferencedContainer = "container:CryptomatorCloudAccess.xcodeproj">
</BuildableReference>
<SkippedTests>
<Test
Identifier = "CloudAccessIntegrationTest">
</Test>
<Test
Identifier = "CloudAccessIntegrationTestWithAuthentication">
</Test>
<Test
Identifier = "CloudProvider_CreateIntermediateFolderTests">
</Test>
<Test
Identifier = "DropboxCloudProviderIntegrationTests">
</Test>
<Test
Identifier = "GoogleDriveAuthenticatorMockTests">
</Test>
<Test
Identifier = "GoogleDriveCloudProviderIntegrationTests">
</Test>
<Test
Identifier = "LocalFileSystemProviderIntegrationTests">
</Test>
<Test
Identifier = "OneDriveCloudProviderIntegrationTests">
</Test>
<Test
Identifier = "PCloudCloudProviderIntegrationTests">
</Test>
<Test
Identifier = "S3CloudProviderIntegrationTests">
</Test>
<Test
Identifier = "VaultFormat6DropboxIntegrationTests">
</Test>
<Test
Identifier = "VaultFormat6GoogleDriveIntegrationTests">
</Test>
<Test
Identifier = "VaultFormat6LocalFileSystemIntegrationTests">
</Test>
<Test
Identifier = "VaultFormat6OneDriveIntegrationTests">
</Test>
<Test
Identifier = "VaultFormat6PCloudIntegrationTests">
</Test>
<Test
Identifier = "VaultFormat6S3IntegrationTests">
</Test>
<Test
Identifier = "VaultFormat6WebDAVIntegrationTests">
</Test>
<Test
Identifier = "VaultFormat7DropboxIntegrationTests">
</Test>
<Test
Identifier = "VaultFormat7GoogleDriveIntegrationTests">
</Test>
<Test
Identifier = "VaultFormat7LocalFileSystemIntegrationTests">
</Test>
<Test
Identifier = "VaultFormat7OneDriveIntegrationTests">
</Test>
<Test
Identifier = "VaultFormat7PCloudIntegrationTests">
</Test>
<Test
Identifier = "VaultFormat7S3IntegrationTests">
</Test>
<Test
Identifier = "VaultFormat7WebDAVIntegrationTests">
</Test>
<Test
Identifier = "WebDAVCloudProviderIntegrationTests">
</Test>
</SkippedTests>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ Begin the authentication flow:

```swift
let tokenStore = BoxTokenStore()
let credential = BoxCredential(tokenStore: tokenStore)
let viewController = ... // the presenting `UIViewController`
BoxAuthenticator.authenticate(credential: credential, from: viewController).then {
// authentication successful
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//
// BoxAuthenticatorMock.swift
// CryptomatorCloudAccessIntegrationTests
//
// Created by Majid Achhoud on 25.04.24.
// Copyright © 2024 Skymatic GmbH. All rights reserved.
//

import Foundation
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,14 @@ import Promises
#endif

class BoxCredentialMock: BoxCredential {
let tokenStore: MemoryTokenStore

init() {
BoxSetup.constants = BoxSetup(clientId: "", clientSecret: "", sharedContainerIdentifier: "")
self.tokenStore = MemoryTokenStore()
tokenStore.tokenInfo = TokenInfo(accessToken: IntegrationTestSecrets.boxAccessToken, refreshToken: IntegrationTestSecrets.boxRefreshToken, expiresIn: 3600, tokenType: "bearer")
super.init(tokenStore: tokenStore)
super.init(tokenStore: MemoryTokenStore())
client = BoxSDK.getClient(token: IntegrationTestSecrets.boxDeveloperToken)
}

override func deauthenticate() -> Promise<Void> {
tokenStore.tokenInfo = TokenInfo(accessToken: "invalid", expiresIn: 0)
client = BoxSDK.getClient(token: "invalid")
return Promise(())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
//
// VaultFormat6BoxIntegrationTests.swift
// CryptomatorCloudAccessIntegrationTests
//
// Created by Majid Achhoud on 29.04.24.
// Copyright © 2024 Skymatic GmbH. All rights reserved.
//

import XCTest
#if canImport(CryptomatorCloudAccessCore)
@testable import CryptomatorCloudAccessCore
#else
@testable import CryptomatorCloudAccess
#endif
@testable import Promises

class VaultFormat6BoxIntegrationTests: CloudAccessIntegrationTest {
override class var defaultTestSuite: XCTestSuite {
return XCTestSuite(forTestCaseClass: VaultFormat6BoxIntegrationTests.self)
}

private static let credential = BoxCredentialMock()
// swiftlint:disable:next force_try
private static let cloudProvider = try! BoxCloudProvider(credential: credential)
private static let vaultPath = CloudPath("/iOS-IntegrationTests-VaultFormat6")

override class func setUp() {
integrationTestParentCloudPath = CloudPath("/")
let setUpPromise = cloudProvider.deleteFolderIfExisting(at: vaultPath).then {
DecoratorFactory.createNewVaultFormat6(delegate: cloudProvider, vaultPath: vaultPath, password: "IntegrationTest")
}.then { decorator in
setUpProvider = decorator
}
guard waitForPromises(timeout: 60.0) else {
classSetUpError = IntegrationTestError.oneTimeSetUpTimeout
return
}
if let error = setUpPromise.error {
classSetUpError = error
return
}
super.setUp()
}

override func setUpWithError() throws {
try super.setUpWithError()
let credential = BoxCredentialMock()
let cloudProvider = try BoxCloudProvider(credential: credential)
let setUpPromise = DecoratorFactory.createFromExistingVaultFormat6(delegate: cloudProvider, vaultPath: VaultFormat6BoxIntegrationTests.vaultPath, password: "IntegrationTest").then { decorator in
self.provider = decorator
}
guard waitForPromises(timeout: 60.0) else {
if let error = setUpPromise.error {
throw error
}
throw IntegrationTestError.setUpTimeout
}
}

override func createLimitedCloudProvider() throws -> CloudProvider {
let credential = BoxCredentialMock()
let limitedDelegate = try BoxCloudProvider(credential: credential, maxPageSize: maxPageSizeForLimitedCloudProvider)
let setUpPromise = DecoratorFactory.createFromExistingVaultFormat6(delegate: limitedDelegate, vaultPath: VaultFormat6BoxIntegrationTests.vaultPath, password: "IntegrationTest").then { decorator in
self.provider = decorator
}
guard waitForPromises(timeout: 60.0) else {
if let error = setUpPromise.error {
throw error
}
throw IntegrationTestError.setUpTimeout
}
return try XCTUnwrap(setUpPromise.value)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
//
// VaultFormat7BoxIntegrationTests.swift
// CryptomatorCloudAccessIntegrationTests
//
// Created by Majid Achhoud on 29.04.24.
// Copyright © 2024 Skymatic GmbH. All rights reserved.
//

import XCTest
#if canImport(CryptomatorCloudAccessCore)
@testable import CryptomatorCloudAccessCore
#else
@testable import CryptomatorCloudAccess
#endif
@testable import Promises

class VaultFormat7BoxIntegrationTests: CloudAccessIntegrationTest {
override class var defaultTestSuite: XCTestSuite {
return XCTestSuite(forTestCaseClass: VaultFormat7BoxIntegrationTests.self)
}

private static let credential = BoxCredentialMock()
// swiftlint:disable:next force_try
private static let cloudProvider = try! BoxCloudProvider(credential: credential)
private static let vaultPath = CloudPath("/iOS-IntegrationTests-VaultFormat7")

override class func setUp() {
integrationTestParentCloudPath = CloudPath("/")
let setUpPromise = cloudProvider.deleteFolderIfExisting(at: vaultPath).then {
DecoratorFactory.createNewVaultFormat7(delegate: cloudProvider, vaultPath: vaultPath, password: "IntegrationTest")
}.then { decorator in
setUpProvider = decorator
}
guard waitForPromises(timeout: 60.0) else {
classSetUpError = IntegrationTestError.oneTimeSetUpTimeout
return
}
if let error = setUpPromise.error {
classSetUpError = error
return
}
super.setUp()
}

override func setUpWithError() throws {
try super.setUpWithError()
let credential = BoxCredentialMock()
let cloudProvider = try BoxCloudProvider(credential: credential)
let setUpPromise = DecoratorFactory.createFromExistingVaultFormat7(delegate: cloudProvider, vaultPath: VaultFormat7BoxIntegrationTests.vaultPath, password: "IntegrationTest").then { decorator in
self.provider = decorator
}
guard waitForPromises(timeout: 60.0) else {
if let error = setUpPromise.error {
throw error
}
throw IntegrationTestError.setUpTimeout
}
}

override func createLimitedCloudProvider() throws -> CloudProvider {
let credential = BoxCredentialMock()
let limitedDelegate = try BoxCloudProvider(credential: credential, maxPageSize: maxPageSizeForLimitedCloudProvider)
let setUpPromise = DecoratorFactory.createFromExistingVaultFormat7(delegate: limitedDelegate, vaultPath: VaultFormat7BoxIntegrationTests.vaultPath, password: "IntegrationTest").then { decorator in
self.provider = decorator
}
guard waitForPromises(timeout: 60.0) else {
if let error = setUpPromise.error {
throw error
}
throw IntegrationTestError.setUpTimeout
}
return try XCTUnwrap(setUpPromise.value)
}
}
5 changes: 2 additions & 3 deletions Tests/CryptomatorCloudAccessIntegrationTests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ If you would like to run integration tests that require authentication, you have

```sh
#!/bin/sh
export BOX_ACCESS_TOKEN=...
export BOX_REFRESH_TOKEN=...
export BOX_DEVELOPER_TOKEN=...
export DROPBOX_ACCESS_TOKEN=...
export GOOGLE_DRIVE_CLIENT_ID=...
export GOOGLE_DRIVE_REFRESH_TOKEN=...
Expand Down Expand Up @@ -37,7 +36,7 @@ If you are building via a CI system, set these secret environment variables acco

#### Box

To get the access token for Box, generate a developer token in the Box Developer Portal. For more detailed instructions, check out the [OAuth 2.0 Documentation from Box](https://developer.box.com/guides/authentication/oauth2/).
To get a developer token for Box, generate it in the Box Developer Portal, keeping in mind that it expires after 60 minutes. For more detailed instructions, check out the [OAuth 2.0 Documentation from Box](https://developer.box.com/guides/authentication/oauth2/).

To obtain the refresh token from Box, it is recommended to extract it from `authenticate` after a successful login. The easiest way to do this is to set a breakpoint inside the `BoxAuthenticator`:

Expand Down
3 changes: 1 addition & 2 deletions create-integration-test-secrets-file.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ import CryptomatorCloudAccess
import Foundation
enum IntegrationTestSecrets {
static let boxAccessToken = "${BOX_ACCESS_TOKEN}"
static let boxRefreshToken = "${BOX_REFRESH_TOKEN}"
static let boxDeveloperToken = "${BOX_DEVELOPER_TOKEN}"
static let dropboxAccessToken = "${DROPBOX_ACCESS_TOKEN}"
static let googleDriveClientId = "${GOOGLE_DRIVE_CLIENT_ID}"
static let googleDriveRefreshToken = "${GOOGLE_DRIVE_REFRESH_TOKEN}"
Expand Down

0 comments on commit 995defc

Please sign in to comment.