|
| 1 | +//----------------------------------------------------------------------------- |
| 2 | +// <copyright file="DropboxClientTokenTests.cs" company="Dropbox Inc"> |
| 3 | +// Copyright (c) Dropbox Inc. All rights reserved. |
| 4 | +// </copyright> |
| 5 | +//----------------------------------------------------------------------------- |
| 6 | + |
| 7 | +namespace Dropbox.Api.Unit.Tests |
| 8 | +{ |
| 9 | + using System; |
| 10 | + using Microsoft.VisualStudio.TestTools.UnitTesting; |
| 11 | + |
| 12 | + /// <summary> |
| 13 | + /// Tests token validation and normalization for Dropbox clients. |
| 14 | + /// </summary> |
| 15 | + [TestClass] |
| 16 | + public class DropboxClientTokenTests |
| 17 | + { |
| 18 | + /// <summary> |
| 19 | + /// Verifies an empty access token is rejected by the user client. |
| 20 | + /// </summary> |
| 21 | + [TestMethod] |
| 22 | + public void TestDropboxClientRejectsEmptyAccessToken() |
| 23 | + { |
| 24 | + Assert.ThrowsExactly<ArgumentException>(() => CreateDropboxClientWithAccessToken(string.Empty)); |
| 25 | + } |
| 26 | + |
| 27 | + /// <summary> |
| 28 | + /// Verifies an empty refresh token is rejected by the user client. |
| 29 | + /// </summary> |
| 30 | + [TestMethod] |
| 31 | + public void TestDropboxClientRejectsEmptyRefreshToken() |
| 32 | + { |
| 33 | + Assert.ThrowsExactly<ArgumentException>(() => CreateDropboxClientWithRefreshToken(string.Empty)); |
| 34 | + } |
| 35 | + |
| 36 | + /// <summary> |
| 37 | + /// Verifies an empty access token is rejected by the team client. |
| 38 | + /// </summary> |
| 39 | + [TestMethod] |
| 40 | + public void TestDropboxTeamClientRejectsEmptyAccessToken() |
| 41 | + { |
| 42 | + Assert.ThrowsExactly<ArgumentException>(() => CreateDropboxTeamClientWithAccessToken(string.Empty)); |
| 43 | + } |
| 44 | + |
| 45 | + /// <summary> |
| 46 | + /// Verifies an empty refresh token is rejected by the team client. |
| 47 | + /// </summary> |
| 48 | + [TestMethod] |
| 49 | + public void TestDropboxTeamClientRejectsEmptyRefreshToken() |
| 50 | + { |
| 51 | + Assert.ThrowsExactly<ArgumentException>(() => CreateDropboxTeamClientWithRefreshToken(string.Empty)); |
| 52 | + } |
| 53 | + |
| 54 | + /// <summary> |
| 55 | + /// Verifies empty token strings are normalized to missing tokens. |
| 56 | + /// </summary> |
| 57 | + [TestMethod] |
| 58 | + public void TestRequestHandlerOptionsNormalizeEmptyTokens() |
| 59 | + { |
| 60 | + var emptyAccessTokenOptions = new DropboxRequestHandlerOptions( |
| 61 | + new DropboxClientConfig(), |
| 62 | + string.Empty, |
| 63 | + "refresh-token", |
| 64 | + null, |
| 65 | + "app-key", |
| 66 | + null); |
| 67 | + var emptyRefreshTokenOptions = new DropboxRequestHandlerOptions( |
| 68 | + new DropboxClientConfig(), |
| 69 | + "access-token", |
| 70 | + string.Empty, |
| 71 | + null, |
| 72 | + "app-key", |
| 73 | + null); |
| 74 | + |
| 75 | + Assert.IsNull(emptyAccessTokenOptions.OAuth2AccessToken); |
| 76 | + Assert.AreEqual("refresh-token", emptyAccessTokenOptions.OAuth2RefreshToken); |
| 77 | + Assert.AreEqual("access-token", emptyRefreshTokenOptions.OAuth2AccessToken); |
| 78 | + Assert.IsNull(emptyRefreshTokenOptions.OAuth2RefreshToken); |
| 79 | + } |
| 80 | + |
| 81 | + private static void CreateDropboxClientWithAccessToken(string token) |
| 82 | + { |
| 83 | + using (var client = new DropboxClient(token)) |
| 84 | + { |
| 85 | + } |
| 86 | + } |
| 87 | + |
| 88 | + private static void CreateDropboxClientWithRefreshToken(string token) |
| 89 | + { |
| 90 | + using (var client = new DropboxClient(token, "app-key")) |
| 91 | + { |
| 92 | + } |
| 93 | + } |
| 94 | + |
| 95 | + private static void CreateDropboxTeamClientWithAccessToken(string token) |
| 96 | + { |
| 97 | + using (var client = new DropboxTeamClient(token)) |
| 98 | + { |
| 99 | + } |
| 100 | + } |
| 101 | + |
| 102 | + private static void CreateDropboxTeamClientWithRefreshToken(string token) |
| 103 | + { |
| 104 | + using (var client = new DropboxTeamClient(token, "app-key")) |
| 105 | + { |
| 106 | + } |
| 107 | + } |
| 108 | + } |
| 109 | +} |
0 commit comments