コード例 #1
0
        public void DirectoryAllowed()
        {
            var url = TokenSigner.SignUrl(t =>
            {
                t.Url         = "https://token-tester.b-cdn.net/abc/";
                t.SecurityKey = "SecurityKey";
                t.ExpiresAt   = new DateTimeOffset(2020, 08, 21, 15, 43, 07, TimeSpan.Zero);
                t.IsDirectory = true;
            });

            url.ShouldBe <string>("https://token-tester.b-cdn.net/bcdn_token=e0fYj-NC_YeROS_0gTGvscP7HR_Du78I7WBVSDV8P4E&expires=1598024587/abc/");
        }
コード例 #2
0
        public void WithPathAllowed()
        {
            var url = TokenSigner.SignUrl(t =>
            {
                t.Url         = "https://token-tester.b-cdn.net/abc/300kb.jpg";
                t.SecurityKey = "SecurityKey";
                t.ExpiresAt   = new DateTimeOffset(2020, 08, 21, 15, 43, 07, TimeSpan.Zero);
                t.TokenPath   = "/abc";
            });

            url.ShouldBe <string>("https://token-tester.b-cdn.net/abc/300kb.jpg?token=xwPaUzEMSgOZ7yl86K55G7len9n1UMiuP36IAyw8Mjs&token_path=%2Fabc&expires=1598024587");
        }
コード例 #3
0
        public void WithIPAddressAllowed()
        {
            var url = TokenSigner.SignUrl(t =>
            {
                t.Url         = "https://token-tester.b-cdn.net/300kb.jpg";
                t.SecurityKey = "SecurityKey";
                t.ExpiresAt   = new DateTimeOffset(2020, 08, 21, 15, 43, 07, TimeSpan.Zero);
                t.UserIp      = "1.2.3.4";
            });

            url.ShouldBe <string>("https://token-tester.b-cdn.net/300kb.jpg?token=xUWMwsZcXfzxMvTTFiKAN6if1WBhDZV1Shjt_GOrjG0&expires=1598024587");
        }
コード例 #4
0
        public void WithCountriesDisallowed()
        {
            var url = TokenSigner.SignUrl(t =>
            {
                t.Url              = "https://token-tester.b-cdn.net/300kb.jpg";
                t.SecurityKey      = "SecurityKey";
                t.CountriesBlocked = new List <string> {
                    "CA"
                };
                t.ExpiresAt = new DateTimeOffset(2020, 08, 21, 15, 43, 07, TimeSpan.Zero);
            });

            url.ShouldBe <string>("https://token-tester.b-cdn.net/300kb.jpg?token=bq6dlNKcoVbTrzCJepE5gHoC436eTtz97Ruk89V8tmU&token_countries_blocked=CA&expires=1598024587");
        }
コード例 #5
0
        public void WithCountriesAllowed()
        {
            var url = TokenSigner.SignUrl(t =>
            {
                t.Url              = "https://token-tester.b-cdn.net/300kb.jpg";
                t.SecurityKey      = "SecurityKey";
                t.CountriesAllowed = new List <string> {
                    "CA"
                };
                t.ExpiresAt = new DateTimeOffset(2020, 08, 21, 15, 43, 07, TimeSpan.Zero);
                t.TokenPath = "/";
            });

            url.ShouldBe <string>("https://token-tester.b-cdn.net/300kb.jpg?token=3ZdIIg1-PB_UOF62lQIqfT4MWr2ENIdd0KWnQVuej3w&token_countries=CA&token_path=%2F&expires=1598024587");
        }
コード例 #6
0
        public void WithIPAddressAllowed_ConvienenceMethod()
        {
            var utcNowPlusOneHour = DateTimeOffset.UtcNow.Add(TimeSpan.FromHours(1));

            var url = TokenSigner.SignUrl(t =>
            {
                t.Url         = "https://token-tester.b-cdn.net/300kb.jpg";
                t.SecurityKey = "SecurityKey";
                t.ExpiresAt   = utcNowPlusOneHour;
                t.UserIp      = "1.2.3.4";
            });

            var urlConvienent = TokenSigner.SignUrl("SecurityKey", "https://token-tester.b-cdn.net/300kb.jpg", utcNowPlusOneHour, "1.2.3.4");

            urlConvienent.ShouldBe <string>(url);
        }