示例#1
0
        public void GetBlob_throws_on_not_HTTP_OK()
        {
            var http = SetupGet(HttpStatusCode.NotFound, new byte[0]);

            Assert.That(() => Client.GetBlob(TestData.Username, Session, http.Object),
                        ExceptionsTest.ThrowsNetworkErrorWithMessage("NotFound (404)"));
        }
示例#2
0
        public void Step1_throws_on_missing_WWW_Authenticate_header()
        {
            var http = SetupStep1(null);

            Assert.That(
                () => Client.Step1(TestData.Credentials, new Client.OtpOptions(), http.Object),
                ExceptionsTest.ThrowsInvalidResponseWithMessage("WWW-Authenticate header"));
        }
示例#3
0
        public void Step2_throws_http_unauthorized()
        {
            var http = SetupStep2(HttpStatusCode.Unauthorized);

            Assert.That(() => Client.Step2(TestData.Credentials,
                                           new Client.OtpOptions(),
                                           TestData.AuthInfo,
                                           http.Object),
                        ExceptionsTest.ThrowsIncorrectCredentialsWithMessage("Username or password"));
        }
示例#4
0
        public void Decrypt_throws_on_invalid_iteration_count()
        {
            var iterations = new[] { new byte[] { 0, 0, 0, 0 }, new byte[] { 0, 0x08, 0, 1 } };

            foreach (var i in iterations)
            {
                Assert.That(DecryptPad("gsencst1\x00\x02".ToBytes().Concat(i).ToArray()),
                            ExceptionsTest.ThrowsParseErrorWithMessage("iteration count"));
            }
        }
示例#5
0
        public void Parse_throws_on_invalid_content_length()
        {
            var lengths = new[] { new byte[] { 0, 0, 0, 0x80 }, new byte[] { 0xFF, 0xFF, 0xFF, 0xFF } };

            foreach (var i in lengths)
            {
                Assert.That(ParsePad("onefile1\x07\x01".ToBytes().Concat(i).ToArray()),
                            ExceptionsTest.ThrowsParseErrorWithMessage("negative"));
            }
        }
示例#6
0
        public void Step2_throws_on_missing_cookies()
        {
            var testCases = new[]
            {
                new string[] {},
                new[] { "sib-auth=auth" },
                new[] { "sib-deviceid=deviceid" },
                new[] { "blah=blah-blah" },
                new[] { "sib-auth=auth", "blah=blah-blah" },
            };

            foreach (var testCase in testCases)
            {
                var http = SetupStep2(testCase);
                Assert.That(() => Client.Step2(TestData.Credentials,
                                               new Client.OtpOptions(),
                                               TestData.AuthInfo,
                                               http.Object),
                            ExceptionsTest.ThrowsInvalidResponseWithMessage("cookie"));
            }
        }
示例#7
0
 public void Logout_throws_on_not_HTTP_OK()
 {
     Assert.That(() => Logout(HttpStatusCode.NotFound),
                 ExceptionsTest.ThrowsNetworkErrorWithMessage("NotFound (404)"));
 }
示例#8
0
 public void Decrypt_throws_on_unsupported_invalid_kdf()
 {
     Assert.That(DecryptPad("gsencst1\x00" + "\x05"),
                 ExceptionsTest.ThrowsParseErrorWithMessage("KDF/encryption type"));
 }
示例#9
0
 public void Decrypt_throws_on_unsupported_sha1_kdf()
 {
     Assert.That(DecryptPad("gsencst1\x00" + "\x01"),
                 ExceptionsTest.ThrowsUnsupportedFeatureWithMessage("SHA-1"));
 }
示例#10
0
 public void Decrypt_throws_on_invalid_signature()
 {
     Assert.That(DecryptPad("invalid!"),
                 ExceptionsTest.ThrowsParseErrorWithMessage("signature"));
 }
示例#11
0
 public void Parse_throws_on_too_short_content()
 {
     Assert.That(ParsePad("onefile1\x07\x01\x02\x00\x00\x00" + "invalid checksum" + "!"),
                 ExceptionsTest.ThrowsParseErrorWithMessage("too short"));
 }
示例#12
0
 public void Parse_throws_on_invalid_checksum()
 {
     Assert.That(ParsePad("onefile1\x07\x01\x01\x00\x00\x00" + "invalid checksum" + "!"),
                 ExceptionsTest.ThrowsParseErrorWithMessage("Checksum"));
 }
示例#13
0
 public void Parse_throws_on_invalid_checksum_type()
 {
     Assert.That(ParsePad("onefile1\x07" + "\x13"),
                 ExceptionsTest.ThrowsParseErrorWithMessage("checksum"));
 }
示例#14
0
 public void Parse_throws_unencrypted_content()
 {
     Assert.That(ParsePad("onefile1" + "\x05"),
                 ExceptionsTest.ThrowsUnsupportedFeatureWithMessage("Unencrypted"));
 }
示例#15
0
 public void ParseJson_throws_on_invalid_json()
 {
     Assert.That(() => OneFile.ParseJson("}{".ToBytes()),
                 ExceptionsTest.ThrowsParseErrorWithMessage("Corrupted"));
 }
示例#16
0
 public void Decrypt_throws_on_too_short_extra()
 {
     Assert.That(DecryptPad("gsencst1\x10\x02\x00\x10\x00\x00\x10saltsaltsaltsalt" + "extra..."),
                 ExceptionsTest.ThrowsParseErrorWithMessage("too short"));
 }
示例#17
0
 public void Decrypt_throws_on_no_content()
 {
     Assert.That(Decrypt("too short".ToBytes()),
                 ExceptionsTest.ThrowsParseErrorWithMessage("too short"));
 }
示例#18
0
 //
 // Helpers
 //
 private static void VerifyThrows(Action action)
 {
     Assert.That(new TestDelegate(action),
                 ExceptionsTest.ThrowsInvalidResponseWithMessage("Invalid auth info"));
 }