Skip to content

Commit

Permalink
Update the test project UI to use scopes (#325)
Browse files Browse the repository at this point in the history
* Update test project
* Make scopes come from one place
  • Loading branch information
YufeiG authored Aug 25, 2021
1 parent a58c516 commit 4a84adb
Show file tree
Hide file tree
Showing 13 changed files with 74 additions and 128 deletions.
7 changes: 3 additions & 4 deletions TestObjectiveDropbox/IntegrationTests/TestAppType.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
#import <Foundation/Foundation.h>

typedef NS_ENUM(NSInteger, ApiAppPermissionType) {
FullDropbox,
TeamMemberFileAccess,
TeamMemberManagement,
FullDropboxScoped,
FullDropboxScopedForTeamTesting,
};

/// Toggle this variable depending on which set of tests you are running.
static ApiAppPermissionType appPermission = (ApiAppPermissionType)FullDropbox;
static ApiAppPermissionType appPermission = (ApiAppPermissionType)FullDropboxScoped;
3 changes: 2 additions & 1 deletion TestObjectiveDropbox/IntegrationTests/TestClasses.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
@class TeamTests;

@interface DropboxTester : NSObject
+ (NSArray<NSString *>*_Nonnull)scopesForTests;
- (nonnull instancetype)initWithUserClient:(DBUserClient *_Nonnull)userClient testData:(TestData *_Nonnull)testData;
- (nonnull instancetype)initWithTestData:(TestData * _Nonnull)testData;

Expand All @@ -29,7 +30,7 @@
@end

@interface DropboxTeamTester : NSObject

+ (NSArray<NSString *>*_Nonnull)scopesForTests;
- (nonnull instancetype)initWithTeamClient:(DBTeamClient *_Nonnull)teamClient testData:(TestData * _Nonnull)testData;
- (nonnull instancetype)initWithTestData:(TestData * _Nonnull)testData;

Expand Down
12 changes: 12 additions & 0 deletions TestObjectiveDropbox/IntegrationTests/TestClasses.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ void MyLog(NSString *format, ...) {
}

@implementation DropboxTester
+ (NSArray<NSString *>*)scopesForTests {
return [@"account_info.read files.content.read files.content.write files.metadata.read files.metadata.write sharing.write sharing.read" componentsSeparatedByString:@" "];
}

- (instancetype)initWithUserClient:(DBUserClient *)userClient testData:(TestData *)testData {
self = [super init];
if (self) {
Expand Down Expand Up @@ -228,6 +232,14 @@ - (void)testUsersEndpoints:(void (^)(void))nextTest {
@end

@implementation DropboxTeamTester
+ (NSArray<NSString *>*)scopesForTests {
NSString *scopesForTeamRoutesTests = @"groups.read groups.write members.delete members.read members.write sessions.list team_data.member team_info.read";
NSString *scopesForMemberFileAccessUserTests = @"files.content.write files.content.read sharing.write account_info.read";
return [[NSString stringWithFormat:@"%@ %@",
scopesForTeamRoutesTests,
scopesForMemberFileAccessUserTests] componentsSeparatedByString:@" "];
}

- (instancetype)initWithTeamClient:(DBTeamClient *)teamClient testData:(TestData * _Nonnull)testData {
self = [super init];
if (self) {
Expand Down
6 changes: 0 additions & 6 deletions TestObjectiveDropbox/IntegrationTests/TestData.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,4 @@
@property(nonatomic, copy) NSString * _Nonnull fullDropboxAppKey;
@property(nonatomic, copy) NSString * _Nonnull fullDropboxAppSecret;

@property(nonatomic, copy) NSString * _Nonnull teamMemberFileAccessAppKey;
@property(nonatomic, copy) NSString * _Nonnull teamMemberFileAccessAppSecret;

@property(nonatomic, copy) NSString * _Nonnull teamMemberManagementAppKey;
@property(nonatomic, copy) NSString * _Nonnull teamMemberManagementAppSecret;

@end
6 changes: 0 additions & 6 deletions TestObjectiveDropbox/IntegrationTests/TestData.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,6 @@ - (instancetype)init {
// App key and secret
_fullDropboxAppKey = @"<FULL_DROPBOX_APP_KEY>";
_fullDropboxAppSecret = @"<FULL_DROPBOX_APP_SECRET>";

_teamMemberFileAccessAppKey = @"<TEAM_MEMBER_FILE_ACCESS_APP_KEY>";
_teamMemberFileAccessAppSecret = @"<FULL_DROPBOX_APP_SECRET>";

_teamMemberManagementAppKey = @"<TEAM_MEMBER_MANAGEMENT_APP_KEY>";
_teamMemberManagementAppSecret = @"<TEAM_MEMBER_MANAGEMENT_APP_SECRET>";
}
return self;
}
Expand Down
22 changes: 6 additions & 16 deletions TestObjectiveDropbox/TestObjectiveDropbox_iOS/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(

TestData *data = [TestData new];

if ([data.fullDropboxAppSecret containsString:@"<"] ||
[data.teamMemberFileAccessAppKey containsString:@"<"] ||
[data.teamMemberManagementAppKey containsString:@"<"]) {
if ([data.fullDropboxAppSecret containsString:@"<"]) {
NSLog(@"\n\n\nMust set test data (in TestData.h) before launching app.\n\n\nTerminating.....\n\n");
exit(0);
}
Expand All @@ -51,10 +49,6 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
delegateQueue:[NSOperationQueue new]
forceForegroundSession:NO
sharedContainerIdentifier:[NSBundle mainBundle].bundleIdentifier];
DBTransportDefaultConfig *transportConfigTeamFileAccess =
[[DBTransportDefaultConfig alloc] initWithAppKey:data.teamMemberFileAccessAppKey appSecret:data.teamMemberFileAccessAppSecret];
DBTransportDefaultConfig *transportConfigTeamManagement =
[[DBTransportDefaultConfig alloc] initWithAppKey:data.teamMemberManagementAppKey appSecret:data.teamMemberManagementAppSecret];

void (^networkGlobalResponseBlock)(DBRequestError *, DBTask *) =
^(DBRequestError *networkError, DBTask *restartTask) {
Expand All @@ -70,14 +64,11 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
[DBGlobalErrorResponseHandler registerNetworkErrorResponseBlock:networkGlobalResponseBlock];

switch (appPermission) {
case FullDropbox:
case FullDropboxScoped:
[DBClientsManager setupWithTransportConfig:transportConfigFullDropbox];
break;
case TeamMemberFileAccess:
[DBClientsManager setupWithTeamTransportConfig:transportConfigTeamFileAccess];
break;
case TeamMemberManagement:
[DBClientsManager setupWithTeamTransportConfig:transportConfigTeamManagement];
case FullDropboxScopedForTeamTesting:
[DBClientsManager setupWithTeamTransportConfig:transportConfigFullDropbox];
break;
}

Expand Down Expand Up @@ -162,12 +153,11 @@ - (BOOL)db_handleAuthUrl:(NSURL *)url {

BOOL handled = NO;
switch (appPermission) {
case FullDropbox: {
case FullDropboxScoped: {
handled = [DBClientsManager handleRedirectURL:url completion:completion];
break;
}
case TeamMemberFileAccess:
case TeamMemberManagement:
case FullDropboxScopedForTeamTesting:
handled = [DBClientsManager handleRedirectURLTeam:url completion:completion];
break;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="15505" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="18122" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<device id="retina4_7" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15510"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="18093"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand All @@ -19,50 +19,43 @@
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="0Il-qF-Vab">
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="0Il-qF-Vab">
<rect key="frame" x="104.5" y="438.5" width="166" height="30"/>
<state key="normal" title="Unlink Dropbox Account"/>
<connections>
<action selector="unlinkButtonPressed:" destination="BYZ-38-t0r" eventType="touchUpInside" id="lzJ-ZW-kww"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="b9W-gk-MoP">
<rect key="frame" x="111.5" y="258.5" width="152" height="30"/>
<state key="normal" title="Link Dropbox Account"/>
<connections>
<action selector="tokenFlowlinkButton:" destination="BYZ-38-t0r" eventType="touchUpInside" id="L1r-FM-vZV"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="db5-aq-giW">
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="db5-aq-giW">
<rect key="frame" x="140.5" y="118.5" width="94" height="30"/>
<state key="normal" title="Run API Tests"/>
<connections>
<action selector="runTestsButtonPressed:" destination="BYZ-38-t0r" eventType="touchUpInside" id="Lj1-FW-imk"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="lAs-Sd-MXl">
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="lAs-Sd-MXl">
<rect key="frame" x="38" y="318.5" width="299" height="30"/>
<state key="normal" title="Read info and return to official Dropbox app"/>
<connections>
<action selector="openWithButtonPressedRunTests:" destination="BYZ-38-t0r" eventType="touchUpInside" id="2jH-2n-WvR"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="KMW-d6-mUc">
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="KMW-d6-mUc">
<rect key="frame" x="107.5" y="158.5" width="160" height="30"/>
<state key="normal" title="Run BatchUpload Tests"/>
<connections>
<action selector="runBatchUploadTestsButtonPressed:" destination="BYZ-38-t0r" eventType="touchUpInside" id="dhR-J7-UtW"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="KTl-EQ-KEH">
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="KTl-EQ-KEH">
<rect key="frame" x="94.5" y="198.5" width="186" height="30"/>
<state key="normal" title="Run Global Response Tests"/>
<connections>
<action selector="runGlobalResponseTestsButtonPressed:" destination="BYZ-38-t0r" eventType="touchUpInside" id="W88-Xe-Tty"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="luI-bu-yCb">
<rect key="frame" x="52" y="288" width="270" height="30"/>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="luI-bu-yCb">
<rect key="frame" x="52.5" y="288.5" width="270" height="30"/>
<state key="normal" title="Link Dropbox Account (pkce code flow)"/>
<connections>
<action selector="codeFlowlinkButton:" destination="BYZ-38-t0r" eventType="touchUpInside" id="y4x-3n-29X"/>
Expand All @@ -71,8 +64,6 @@
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="b9W-gk-MoP" firstAttribute="centerY" secondItem="8bC-Xf-vdC" secondAttribute="centerY" constant="-60" id="AKt-Sh-DWa"/>
<constraint firstItem="b9W-gk-MoP" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="JeO-KH-8c6"/>
<constraint firstItem="0Il-qF-Vab" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="KZa-p9-Tp7"/>
<constraint firstItem="KMW-d6-mUc" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="O2J-vQ-A1K"/>
<constraint firstItem="db5-aq-giW" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="O8l-MN-ZX0"/>
Expand All @@ -93,7 +84,6 @@
<outlet property="runBatchUploadTestsButton" destination="KMW-d6-mUc" id="Ody-5w-o9z"/>
<outlet property="runGlobalResponseTestsButton" destination="KTl-EQ-KEH" id="Ion-L3-Ck9"/>
<outlet property="runTestsButton" destination="db5-aq-giW" id="UYY-YH-dIy"/>
<outlet property="tokenFlowlinkButton" destination="b9W-gk-MoP" id="DvX-Jl-kU2"/>
<outlet property="unlinkButton" destination="0Il-qF-Vab" id="oAz-BA-Qf0"/>
</connections>
</viewController>
Expand Down
33 changes: 15 additions & 18 deletions TestObjectiveDropbox/TestObjectiveDropbox_iOS/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

@interface ViewController ()

@property (weak, nonatomic) IBOutlet UIButton *tokenFlowlinkButton;
@property (weak, nonatomic) IBOutlet UIButton *codeFlowlinkButton;
@property (weak, nonatomic) IBOutlet UIButton *runTestsButton;
@property (weak, nonatomic) IBOutlet UIButton *unlinkButton;
Expand All @@ -29,17 +28,18 @@ @interface ViewController ()

@implementation ViewController

- (IBAction)tokenFlowlinkButton:(id)sender {
[DBClientsManager authorizeFromController:[UIApplication sharedApplication]
controller:self
openURL:^(NSURL *url) {
[[UIApplication sharedApplication] openURL:url];
}];
}

- (IBAction)codeFlowlinkButton:(id)sender {
NSArray<NSString*>*scopes = @[];
switch (appPermission) {
case FullDropboxScoped:
scopes = [DropboxTester scopesForTests];
break;
case FullDropboxScopedForTeamTesting:
scopes = [DropboxTeamTester scopesForTests];
break;
}
DBScopeRequest *scopeRequest = [[DBScopeRequest alloc] initWithScopeType:DBScopeTypeUser
scopes:@[@"account_info.read"]
scopes:scopes
includeGrantedScopes:NO];
[DBClientsManager authorizeFromControllerV2:[UIApplication sharedApplication]
controller:self
Expand All @@ -58,14 +58,13 @@ - (IBAction)runTestsButtonPressed:(id)sender {
};

switch (appPermission) {
case FullDropbox:
case FullDropboxScoped:
[[[DropboxTester alloc] initWithTestData:data] testAllUserAPIEndpoints:unlink asMember:NO];
break;
case TeamMemberFileAccess:
[[[DropboxTeamTester alloc] initWithTestData:data] testAllTeamMemberFileAcessActions:unlink];
break;
case TeamMemberManagement:
[[[DropboxTeamTester alloc] initWithTestData:data] testAllTeamMemberManagementActions:unlink];
case FullDropboxScopedForTeamTesting:
[[[DropboxTeamTester alloc] initWithTestData:data] testAllTeamMemberFileAcessActions:^() {
[[[DropboxTeamTester alloc] initWithTestData:data] testAllTeamMemberManagementActions:unlink];
}];
break;
}
}
Expand Down Expand Up @@ -149,14 +148,12 @@ - (void)didReceiveMemoryWarning {

- (void)checkButtons {
if ([DBClientsManager authorizedClient] || [DBClientsManager authorizedTeamClient]) {
_tokenFlowlinkButton.hidden = YES;
_codeFlowlinkButton.hidden = YES;
_unlinkButton.hidden = NO;
_runTestsButton.hidden = NO;
_runBatchUploadTestsButton.hidden = NO;
_runGlobalResponseTestsButton.hidden = NO;
} else {
_tokenFlowlinkButton.hidden = NO;
_codeFlowlinkButton.hidden = NO;
_unlinkButton.hidden = YES;
_runTestsButton.hidden = YES;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
#import <ObjectiveDropboxOfficial/ObjectiveDropboxOfficial.h>
#import "TestAuthTokenGenerator.h"

static NSString *scopesForFileRoutesTests = @"account_info.read files.content.read files.content.write files.metadata.read files.metadata.write sharing.write sharing.read";

@interface FileRoutesTests : XCTestCase
@end

Expand All @@ -17,7 +15,7 @@ @implementation FileRoutesTests {

- (DBUserClient *)createUserClient {
self.continueAfterFailure = NO;
// You need an API app with the "Full Dropbox" permission type and at least the scopes in scopesForFileRoutesTests
// You need an API app with the "Full Dropbox" permission type and at least the scopes in DropoboxTester.scopesForTests
// and no team scopes.
// You can create one for testing here: https://www.dropbox.com/developers/apps/create
// The 'App key' will be on the app's info page.
Expand All @@ -27,7 +25,7 @@ - (DBUserClient *)createUserClient {
NSString *fileRoutesTestsAuthToken = [TestAuthTokenGenerator
refreshToken:[TestAuthTokenGenerator environmentVariableForKey:@"FULL_DROPBOX_TESTER_USER_REFRESH_TOKEN"]
apiKey:apiAppKey
scopes:[scopesForFileRoutesTests componentsSeparatedByString:@" "]];
scopes:[DropboxTester scopesForTests]];
XCTAssertNotNil(fileRoutesTestsAuthToken, @"Error obtaining auth token.");

_delegateQueue = [[NSOperationQueue alloc] init];
Expand Down
Loading

0 comments on commit 4a84adb

Please sign in to comment.