diff --git a/Box.V2.Test/BoxFilesManagerTest.cs b/Box.V2.Test/BoxFilesManagerTest.cs index d00b00250..c01a96803 100644 --- a/Box.V2.Test/BoxFilesManagerTest.cs +++ b/Box.V2.Test/BoxFilesManagerTest.cs @@ -417,7 +417,7 @@ public async Task CopyFile_ValidResponse_ValidFile() public async Task CreateFileSharedLink_ValidResponse_ValidFile() { /*** Arrange ***/ - var responseString = "{ \"type\": \"file\", \"id\": \"5000948880\", \"sequence_id\": \"3\", \"etag\": \"3\", \"sha1\": \"134b65991ed521fcfe4724b7d814ab8ded5185dc\", \"name\": \"tigers.jpeg\", \"description\": \"a picture of tigers\", \"size\": 629644, \"path_collection\": { \"total_count\": 2, \"entries\": [ { \"type\": \"folder\", \"id\": \"0\", \"sequence_id\": null, \"etag\": null, \"name\": \"All Files\" }, { \"type\": \"folder\", \"id\": \"11446498\", \"sequence_id\": \"1\", \"etag\": \"1\", \"name\": \"Pictures\" } ] }, \"created_at\": \"2012-12-12T10:55:30-08:00\", \"modified_at\": \"2012-12-12T11:04:26-08:00\", \"created_by\": { \"type\": \"user\", \"id\": \"17738362\", \"name\": \"sean rose\", \"login\": \"sean@box.com\" }, \"modified_by\": { \"type\": \"user\", \"id\": \"17738362\", \"name\": \"sean rose\", \"login\": \"sean@box.com\" }, \"owned_by\": { \"type\": \"user\", \"id\": \"17738362\", \"name\": \"sean rose\", \"login\": \"sean@box.com\" }, \"shared_link\": { \"url\": \"https://www.box.com/s/rh935iit6ewrmw0unyul\", \"download_url\": \"https://www.box.com/shared/static/rh935iit6ewrmw0unyul.jpeg\", \"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 } }, \"parent\": { \"type\": \"folder\", \"id\": \"11446498\", \"sequence_id\": \"1\", \"etag\": \"1\", \"name\": \"Pictures\" }, \"item_status\": \"active\" }"; + var responseString = "{ \"type\": \"file\", \"id\": \"5000948880\", \"sequence_id\": \"3\", \"etag\": \"3\", \"sha1\": \"134b65991ed521fcfe4724b7d814ab8ded5185dc\", \"name\": \"tigers.jpeg\", \"description\": \"a picture of tigers\", \"size\": 629644, \"path_collection\": { \"total_count\": 2, \"entries\": [ { \"type\": \"folder\", \"id\": \"0\", \"sequence_id\": null, \"etag\": null, \"name\": \"All Files\" }, { \"type\": \"folder\", \"id\": \"11446498\", \"sequence_id\": \"1\", \"etag\": \"1\", \"name\": \"Pictures\" } ] }, \"created_at\": \"2012-12-12T10:55:30-08:00\", \"modified_at\": \"2012-12-12T11:04:26-08:00\", \"created_by\": { \"type\": \"user\", \"id\": \"17738362\", \"name\": \"sean rose\", \"login\": \"sean@box.com\" }, \"modified_by\": { \"type\": \"user\", \"id\": \"17738362\", \"name\": \"sean rose\", \"login\": \"sean@box.com\" }, \"owned_by\": { \"type\": \"user\", \"id\": \"17738362\", \"name\": \"sean rose\", \"login\": \"sean@box.com\" }, \"shared_link\": { \"url\": \"https://www.box.com/s/rh935iit6ewrmw0unyul\", \"download_url\": \"https://www.box.com/shared/static/rh935iit6ewrmw0unyul.jpeg\", \"vanity_url\": null, \"vanity_name\": \"my-custom-vanity-name\", \"is_password_enabled\": false, \"unshared_at\": null, \"download_count\": 0, \"preview_count\": 0, \"access\": \"open\", \"permissions\": { \"can_download\": true, \"can_preview\": true } }, \"parent\": { \"type\": \"folder\", \"id\": \"11446498\", \"sequence_id\": \"1\", \"etag\": \"1\", \"name\": \"Pictures\" }, \"item_status\": \"active\" }"; Handler.Setup(h => h.ExecuteAsync(It.IsAny())) .Returns(Task.FromResult>(new BoxResponse() { @@ -427,7 +427,8 @@ public async Task CreateFileSharedLink_ValidResponse_ValidFile() var sharedLink = new BoxSharedLinkRequest() { - Access = BoxSharedLinkAccessType.collaborators + Access = BoxSharedLinkAccessType.collaborators, + VanityName = "my-custom-vanity-name" }; /*** Act ***/ @@ -443,6 +444,7 @@ public async Task CreateFileSharedLink_ValidResponse_ValidFile() Assert.AreEqual("sean@box.com", f.CreatedBy.Login); Assert.AreEqual("user", f.CreatedBy.Type); Assert.AreEqual("17738362", f.CreatedBy.Id); + Assert.AreEqual("my-custom-vanity-name", f.SharedLink.VanityName); } [TestMethod] diff --git a/Box.V2.Test/BoxFoldersManagerTest.cs b/Box.V2.Test/BoxFoldersManagerTest.cs index b4b7f0cf7..230b2b8f7 100644 --- a/Box.V2.Test/BoxFoldersManagerTest.cs +++ b/Box.V2.Test/BoxFoldersManagerTest.cs @@ -598,13 +598,14 @@ public async Task CreateFolderSharedLink_ValidResponse_ValidFolder() .Returns(() => Task.FromResult>(new BoxResponse() { Status = ResponseStatus.Success, - ContentString = "{ \"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\": \"sean@box.com\" }, \"modified_by\": { \"type\": \"user\", \"id\": \"17738362\", \"name\": \"sean rose\", \"login\": \"sean@box.com\" }, \"owned_by\": { \"type\": \"user\", \"id\": \"17738362\", \"name\": \"sean rose\", \"login\": \"sean@box.com\" }, \"shared_link\": { \"url\": \"https://www.box.com/s/vspke7y05sb214wjokpk\", \"download_url\": \"https://www.box.com/shared/static/vspke7y05sb214wjokpk\", \"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\": \"upload.Picture.k13sdz1@u.box.com\" }, \"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 } }" + ContentString = "{ \"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\": \"sean@box.com\" }, \"modified_by\": { \"type\": \"user\", \"id\": \"17738362\", \"name\": \"sean rose\", \"login\": \"sean@box.com\" }, \"owned_by\": { \"type\": \"user\", \"id\": \"17738362\", \"name\": \"sean rose\", \"login\": \"sean@box.com\" }, \"shared_link\": { \"url\": \"https://www.box.com/s/vspke7y05sb214wjokpk\", \"download_url\": \"https://www.box.com/shared/static/vspke7y05sb214wjokpk\", \"vanity_url\": null, \"vanity_name\": \"my-custom-vanity-name\", \"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\": \"upload.Picture.k13sdz1@u.box.com\" }, \"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 } }" })); /*** Act ***/ var sharedLink = new BoxSharedLinkRequest() { - Access = BoxSharedLinkAccessType.collaborators + Access = BoxSharedLinkAccessType.collaborators, + VanityName = "my-custom-vanity-name" }; BoxFolder f = await _foldersManager.CreateSharedLinkAsync("0", sharedLink); @@ -615,6 +616,7 @@ public async Task CreateFolderSharedLink_ValidResponse_ValidFolder() Assert.AreEqual("1", f.SequenceId); Assert.AreEqual("1", f.ETag); Assert.AreEqual("Pictures", f.Name); + Assert.AreEqual("my-custom-vanity-name", f.SharedLink.VanityName); } [TestMethod] diff --git a/Box.V2.Test/BoxWebLinksManagerTest.cs b/Box.V2.Test/BoxWebLinksManagerTest.cs index a4ad2ff35..3a755b132 100644 --- a/Box.V2.Test/BoxWebLinksManagerTest.cs +++ b/Box.V2.Test/BoxWebLinksManagerTest.cs @@ -463,7 +463,7 @@ public async Task Copy_ValidResponse() public async Task CreateWebLinkSharedLink_ValidResponse_ValidFile() { /*** Arrange ***/ - var responseString = "{ \"type\": \"web_link\", \"id\": \"5000948880\", \"sequence_id\": \"3\", \"etag\": \"3\", \"sha1\": \"134b65991ed521fcfe4724b7d814ab8ded5185dc\", \"name\": \"tigers.jpeg\", \"description\": \"a picture of tigers\", \"size\": 629644, \"path_collection\": { \"total_count\": 2, \"entries\": [ { \"type\": \"folder\", \"id\": \"0\", \"sequence_id\": null, \"etag\": null, \"name\": \"All Files\" }, { \"type\": \"folder\", \"id\": \"11446498\", \"sequence_id\": \"1\", \"etag\": \"1\", \"name\": \"Pictures\" } ] }, \"created_at\": \"2012-12-12T10:55:30-08:00\", \"modified_at\": \"2012-12-12T11:04:26-08:00\", \"created_by\": { \"type\": \"user\", \"id\": \"17738362\", \"name\": \"sean rose\", \"login\": \"sean@box.com\" }, \"modified_by\": { \"type\": \"user\", \"id\": \"17738362\", \"name\": \"sean rose\", \"login\": \"sean@box.com\" }, \"owned_by\": { \"type\": \"user\", \"id\": \"17738362\", \"name\": \"sean rose\", \"login\": \"sean@box.com\" }, \"shared_link\": { \"url\": \"https://www.box.com/s/rh935iit6ewrmw0unyul\", \"download_url\": \"https://www.box.com/shared/static/rh935iit6ewrmw0unyul.jpeg\", \"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 } }, \"parent\": { \"type\": \"folder\", \"id\": \"11446498\", \"sequence_id\": \"1\", \"etag\": \"1\", \"name\": \"Pictures\" }, \"item_status\": \"active\" }"; + var responseString = "{ \"type\": \"web_link\", \"id\": \"5000948880\", \"sequence_id\": \"3\", \"etag\": \"3\", \"sha1\": \"134b65991ed521fcfe4724b7d814ab8ded5185dc\", \"name\": \"tigers.jpeg\", \"description\": \"a picture of tigers\", \"size\": 629644, \"path_collection\": { \"total_count\": 2, \"entries\": [ { \"type\": \"folder\", \"id\": \"0\", \"sequence_id\": null, \"etag\": null, \"name\": \"All Files\" }, { \"type\": \"folder\", \"id\": \"11446498\", \"sequence_id\": \"1\", \"etag\": \"1\", \"name\": \"Pictures\" } ] }, \"created_at\": \"2012-12-12T10:55:30-08:00\", \"modified_at\": \"2012-12-12T11:04:26-08:00\", \"created_by\": { \"type\": \"user\", \"id\": \"17738362\", \"name\": \"sean rose\", \"login\": \"sean@box.com\" }, \"modified_by\": { \"type\": \"user\", \"id\": \"17738362\", \"name\": \"sean rose\", \"login\": \"sean@box.com\" }, \"owned_by\": { \"type\": \"user\", \"id\": \"17738362\", \"name\": \"sean rose\", \"login\": \"sean@box.com\" }, \"shared_link\": { \"url\": \"https://www.box.com/s/rh935iit6ewrmw0unyul\", \"vanity_name\": \"my-custom-vanity-name\", \"download_url\": \"https://www.box.com/shared/static/rh935iit6ewrmw0unyul.jpeg\", \"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 } }, \"parent\": { \"type\": \"folder\", \"id\": \"11446498\", \"sequence_id\": \"1\", \"etag\": \"1\", \"name\": \"Pictures\" }, \"item_status\": \"active\" }"; IBoxRequest boxRequest = null; var webLinksUri = new Uri(Constants.WebLinksEndpointString); Config.SetupGet(x => x.WebLinksEndpointUri).Returns(webLinksUri); @@ -477,7 +477,8 @@ public async Task CreateWebLinkSharedLink_ValidResponse_ValidFile() var sharedLink = new BoxSharedLinkRequest() { - Access = BoxSharedLinkAccessType.collaborators + Access = BoxSharedLinkAccessType.collaborators, + VanityName = "my-custom-vanity-name" }; /*** Act ***/ @@ -486,12 +487,13 @@ public async Task CreateWebLinkSharedLink_ValidResponse_ValidFile() /*** Assert ***/ Assert.AreEqual(new Uri("https://api.box.com/2.0/web_links/12345"), boxRequest.AbsoluteUri); Assert.AreEqual(RequestMethod.Put, boxRequest.Method); - Assert.AreEqual("{\"shared_link\":{\"access\":\"collaborators\"}}", boxRequest.Payload); + Assert.AreEqual("{\"shared_link\":{\"access\":\"collaborators\",\"vanity_name\":\"my-custom-vanity-name\"}}", boxRequest.Payload); Assert.AreEqual("5000948880", w.Id); Assert.AreEqual("3", w.SequenceId); Assert.AreEqual("3", w.ETag); Assert.AreEqual("https://www.box.com/s/rh935iit6ewrmw0unyul", w.SharedLink.Url); + Assert.AreEqual("my-custom-vanity-name", w.SharedLink.VanityName); } [TestMethod] diff --git a/Box.V2/Models/BoxSharedLink.cs b/Box.V2/Models/BoxSharedLink.cs index f00195d20..6c6e68f7d 100644 --- a/Box.V2/Models/BoxSharedLink.cs +++ b/Box.V2/Models/BoxSharedLink.cs @@ -18,6 +18,7 @@ public class BoxSharedLink public const string FieldPreviewCount = "preview_count"; public const string FieldAccess = "access"; public const string FieldPermissions = "permissions"; + public const string FieldVanityName = "vanity_name"; /// /// The Url of the shared link @@ -73,5 +74,12 @@ public class BoxSharedLink /// [JsonProperty(PropertyName = FieldPermissions)] public virtual BoxPermission Permissions { get; private set; } + + /// + /// Defines a custom vanity name to use in the shared link URL, for example https://app.box.com/v/my-shared-link. + /// Custom URLs should not be used when sharing sensitive content as vanity URLs are a lot easier to guess than regular shared links. + /// + [JsonProperty(PropertyName = FieldVanityName)] + public virtual string VanityName { get; private set; } } } diff --git a/Box.V2/Models/Request/BoxSharedLinkRequest.cs b/Box.V2/Models/Request/BoxSharedLinkRequest.cs index 6675a9640..dfeadd2a3 100644 --- a/Box.V2/Models/Request/BoxSharedLinkRequest.cs +++ b/Box.V2/Models/Request/BoxSharedLinkRequest.cs @@ -53,6 +53,14 @@ public bool ShouldSerializeUnsharedAt() /// [JsonProperty(PropertyName = "password")] public string Password { get; set; } + + /// + /// Defines a custom vanity name to use in the shared link URL, for example https://app.box.com/v/my-shared-link. + /// Custom URLs should not be used when sharing sensitive content as vanity URLs are a lot easier to guess than regular shared links. + /// Vanity name must be at least 12 characters long + /// + [JsonProperty(PropertyName = "vanity_name")] + public string VanityName { get; set; } } }