Skip to content

Commit cbfb57f

Browse files
committed
fix: validate id of box resource when constructed
1 parent fadd695 commit cbfb57f

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

src/classes/BoxFolderTests.cls

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,14 @@ public class BoxFolderTests {
101101

102102
public static testMethod void testGetObjectType() {
103103
BoxApiConnection api = new BoxApiConnection('accesstoken');
104-
BoxFolder folder = new BoxFolder(api, 'folderid');
104+
BoxFolder folder = new BoxFolder(api, '11446498');
105105
System.assertEquals('folder', folder.getObjectType());
106106
}
107107

108108
public static testMethod void testSetInfo() {
109109
String mockResponseBody = '{"type":"folder","id":"11446498","sequence_id":"1","etag":"1","name":"Pictures","created_at":"2012-12-12T10:53:43-08:00","modified_at":"2012-12-12T11:15:04-08:00","description":"Some pictures I took","size":629644,"path_collection":{"total_count":1,"entries":[{"type":"folder","id":"0","sequence_id":null,"etag":null,"name":"All Files"}]},"created_by":{"type":"user","id":"17738362","name":"sean rose","login":"[email protected]"},"modified_by":{"type":"user","id":"17738362","name":"sean rose","login":"[email protected]"},"owned_by":{"type":"user","id":"17738362","name":"sean rose","login":"[email protected]"},"shared_link":{"url":"https://www.box.com/s/vspke7y05sb214wjokpk","download_url":null,"vanity_url":null,"is_password_enabled":false,"unshared_at":null,"download_count":0,"preview_count":0,"access":"open","permissions":{"can_download":true,"can_preview":true}},"folder_upload_email":{"access":"open","email":"[email protected]"},"parent":{"type":"folder","id":"0","sequence_id":null,"etag":null,"name":"All Files"},"item_status":"active","item_collection":{"total_count":1,"entries":[{"type":"file","id":"5000948880","sequence_id":"3","etag":"3","sha1":"134b65991ed521fcfe4724b7d814ab8ded5185dc","name":"tigers.jpeg"}],"offset":0,"limit":100}}';
110110
BoxApiConnection api = new BoxApiConnection('accesstoken');
111-
BoxFolder folder = new BoxFolder(api, 'All Files');
111+
BoxFolder folder = new BoxFolder(api, '11446498');
112112
BoxFolder.Info subfolderInfo = new BoxFolder.Info(mockResponseBody);
113113
BoxFolder.Info parentFolderInfo = new BoxFolder.Info(
114114
subfolderInfo.getValue('parent')

src/classes/BoxResource.cls

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public abstract class BoxResource {
2121
*/
2222
public BoxResource(BoxApiConnection api, String id) {
2323
this.api = api;
24+
validateId(id);
2425
this.id = id;
2526
}
2627

@@ -96,6 +97,20 @@ public abstract class BoxResource {
9697
return (BoxResource.Info) information;
9798
}
9899

100+
/**
101+
* Validates the ID of this resource.
102+
*
103+
* @return void
104+
*/
105+
private void validateId(String id) {
106+
if (String.isNotEmpty(id)) {
107+
System.assert(
108+
id.isNumeric(),
109+
'Expect resource to be constructed with a numeric ID'
110+
);
111+
}
112+
}
113+
99114
public abstract void setInfo(BoxJsonObject jsonObject);
100115

101116
public abstract String getObjectType();

src/classes/BoxWebLinkTests.cls

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class BoxWebLinkTests {
88

99
Test.startTest();
1010
BoxApiConnection api = new BoxApiConnection('accesstoken');
11-
BoxWebLink webLink = new BoxWebLink(api, 'web-link-id');
11+
BoxWebLink webLink = new BoxWebLink(api, '12398550180');
1212
BoxWebLink.Info info = webLink.getWebLinkInfo();
1313
Test.stopTest();
1414

@@ -44,7 +44,7 @@ public class BoxWebLinkTests {
4444

4545
Test.startTest();
4646
BoxApiConnection api = new BoxApiConnection('accesstoken');
47-
BoxWebLink webLink = new BoxWebLink(api, 'web-link-id');
47+
BoxWebLink webLink = new BoxWebLink(api, '12398550180');
4848
BoxWebLink.Info info = webLink.getWebLinkInfo();
4949
info.addValue('description', 'Example page');
5050
BoxWebLink.Info updated = webLink.updateWebLinkInfo(info);
@@ -62,7 +62,7 @@ public class BoxWebLinkTests {
6262

6363
Test.startTest();
6464
BoxApiConnection api = new BoxApiConnection('accesstoken');
65-
BoxWebLink webLink = new BoxWebLink(api, 'web-link-id');
65+
BoxWebLink webLink = new BoxWebLink(api, '12398550180');
6666
Boolean deleteWebLinkResult = webLink.deleteWebLink();
6767
Test.stopTest();
6868

@@ -77,7 +77,7 @@ public class BoxWebLinkTests {
7777

7878
Test.startTest();
7979
BoxApiConnection api = new BoxApiConnection('accesstoken');
80-
BoxWebLink webLink = new BoxWebLink(api, 'web-link-id');
80+
BoxWebLink webLink = new BoxWebLink(api, '12398550180');
8181
BoxWebLink.Info info = webLink.getTrashedWebLinkInfo();
8282
Test.stopTest();
8383

@@ -93,23 +93,23 @@ public class BoxWebLinkTests {
9393

9494
Test.startTest();
9595
BoxApiConnection api = new BoxApiConnection('accesstoken');
96-
BoxWebLink webLink = new BoxWebLink(api, 'web-link-id');
96+
BoxWebLink webLink = new BoxWebLink(api, '12398550180');
9797
BoxWebLink.Info info = webLink.restoreTrashedWebLink();
9898
Test.stopTest();
9999

100100
System.assertEquals('active', info.getValue('item_status'));
101101
}
102102

103103
@isTest
104-
static void permanentlyDeleteWebLinkTEst() {
104+
static void permanentlyDeleteWebLinkTest() {
105105
Test.setMock(
106106
HttpCalloutMock.class,
107107
new BoxTestMockCallout('', 'No Content', 204)
108108
);
109109

110110
Test.startTest();
111111
BoxApiConnection api = new BoxApiConnection('accesstoken');
112-
BoxWebLink webLink = new BoxWebLink(api, 'web-link-id');
112+
BoxWebLink webLink = new BoxWebLink(api, '12398550180');
113113
Boolean permanentlyDeleteWebLinkResult = webLink.permanentlyDeleteWebLink();
114114
Test.stopTest();
115115

0 commit comments

Comments
 (0)