示例#1
0
        public void BuildListOfAccessibleVaults_returns_vaults()
        {
            var accountInfo = JObject.Parse(JsonHttpClientTest.ReadFixture("account-info"));
            var vaults      = Client.BuildListOfAccessibleVaults(accountInfo);

            Assert.That(vaults, Is.EquivalentTo(new[] { "ru74fjxlkipzzctorwj4icrj2a", "4tz67op2kfiapodi5ygprtwn64" }));
        }
示例#2
0
        public void SignOut_throws_on_bad_response()
        {
            var http = MakeJsonHttp(JsonHttpClientTest.SetupPut("{'success': 0}"));

            Assert.That(() => Client.SignOut(http),
                        ExceptionsTest.ThrowsRespondedWithErrorWithMessage("Failed to sign out"));
        }
示例#3
0
        public void DecryptKeys_stores_keys_in_keychain()
        {
            var accountInfo = JObject.Parse(JsonHttpClientTest.ReadFixture("account-info"));
            var keysets     = JObject.Parse(JsonHttpClientTest.ReadFixture("keysets"));
            var keychain    = new Keychain();

            Client.DecryptAllKeys(accountInfo, keysets, ClientInfo, keychain);

            var aesKeys = new[]
            {
                "mp",
                "x4ouqoqyhcnqojrgubso4hsdga",
                "byq5gi5adlasqyy2l2o7iddzvq",
            };

            foreach (var i in aesKeys)
            {
                Assert.That(keychain.GetAes(i), Is.Not.Null);
            }

            var keysetIds = new[]
            {
                "szerdhg2ww2ahjo4ilz57x7cce",
                "yf2ji37vkqdow7pnbo3y37b3lu",
                "srkx3r5c3qgyzsdswfc4awgh2m",
                "sm5hkw3mxwdcwcgljf4kyplwea",
            };

            foreach (var i in keysetIds)
            {
                Assert.That(keychain.GetAes(i), Is.Not.Null);
                Assert.That(keychain.GetRsa(i), Is.Not.Null);
            }
        }
示例#4
0
        public void GetAccountInfo_makes_GET_request_to_specific_url()
        {
            var http = MakeJsonHttp(JsonHttpClientTest.SetupGetWithFixture("get-account-info-response"));

            Client.GetAccountInfo(TestData.SesionKey, http);

            JsonHttpClientTest.VerifyGetUrl(http.Http, "1password.com/api/v1/account");
        }
示例#5
0
        public void GetKeysets_makes_GET_request_to_specific_url()
        {
            var http = MakeJsonHttp(JsonHttpClientTest.SetupGetWithFixture("empty-object-response"));

            Client.GetKeysets(TestData.SesionKey, http);

            JsonHttpClientTest.VerifyGetUrl(http.Http, "1password.com/api/v1/account/keysets");
        }
示例#6
0
        public void SignOut_makes_PUT_request_to_specific_url()
        {
            var http = MakeJsonHttp(JsonHttpClientTest.SetupPut("{'success': 1}"));

            Client.SignOut(http);

            JsonHttpClientTest.VerifyPutUrl(http.Http, "1password.com/api/v1/session/signout");
        }
示例#7
0
        public void ExchangeAForB_makes_POST_request_to_specific_url()
        {
            var http = SetupJsonHttp("exchange-a-for-b-response");

            Srp.ExchangeAForB(0, TestData.MakeSession(), http);

            JsonHttpClientTest.VerifyPostUrl(http, "1password.com/api/v1/auth");
        }
示例#8
0
        public void RegisterDevice_throws_on_error()
        {
            var http = MakeJsonHttp(JsonHttpClientTest.SetupPost("{'success': 0}"));

            Assert.That(() => Client.RegisterDevice(TestData.ClientInfo, http),
                        ExceptionsTest.ThrowsRespondedWithErrorWithMessage(TestData.Uuid)
                        .And.Message.StartsWith("Failed to register"));
        }
示例#9
0
        public void StartNewSession_makes_GET_request_to_specific_url()
        {
            var http = MakeJsonHttp(JsonHttpClientTest.SetupGetWithFixture("start-new-session-response"));

            Client.StartNewSession(TestData.ClientInfo, http);

            JsonHttpClientTest.VerifyGetUrl(http.Http, "1password.com/api/v2/auth");
        }
示例#10
0
        public void RegisterDevice_makes_POST_request_to_specific_url()
        {
            var http = MakeJsonHttp(JsonHttpClientTest.SetupPost("{'success': 1}"));

            Client.RegisterDevice(TestData.ClientInfo, http);

            JsonHttpClientTest.VerifyPostUrl(http.Http, "1password.com/api/v1/device");
        }
示例#11
0
        public void StartNewSession_throws_on_unknown_status()
        {
            var http = MakeJsonHttp(JsonHttpClientTest.SetupGet("{'status': 'unknown'}"));

            Assert.That(() => Client.StartNewSession(TestData.ClientInfo, http),
                        ExceptionsTest.ThrowsInvalidResponseWithMessage("'unknown'")
                        .And.Message.StartsWith("Failed to start a new session"));
        }
示例#12
0
        public void VerifySessionKey_makes_POST_request_to_specific_url()
        {
            var http = MakeJsonHttp(JsonHttpClientTest.SetupPostWithFixture("verify-key-response"));

            Client.VerifySessionKey(TestData.ClientInfo, TestData.Session, TestData.SesionKey, http);

            JsonHttpClientTest.VerifyPostUrl(http.Http, "1password.com/api/v2/auth/verify");
        }
示例#13
0
        public void StartNewSession_throws_on_invalid_json()
        {
            var jsonHttp = new JsonHttpClient(
                JsonHttpClientTest.SetupGet("} invalid json {").Object,
                "");

            Assert.That(() => Client.StartNewSession(TestData.ClientInfo, jsonHttp),
                        ExceptionsTest.ThrowsInvalidResponseWithMessage("Invalid JSON"));
        }
示例#14
0
        public void StartNewSession_throws_on_network_error()
        {
            var jsonHttp = new JsonHttpClient(JsonHttpClientTest.SetupGetWithFailure().Object, "");

            Assert.That(() => Client.StartNewSession(TestData.ClientInfo, jsonHttp),
                        ExceptionsTest.ThrowsReasonWithMessage(
                            ClientException.FailureReason.NetworkError,
                            "request"));
        }
示例#15
0
        public void GetVaultAccounts_with_no_items_work()
        {
            var http     = MakeJsonHttp(JsonHttpClientTest.SetupGetWithFixture("get-vault-with-no-items-response"));
            var keychain = new Keychain();

            keychain.Add(new AesKey("x4ouqoqyhcnqojrgubso4hsdga",
                                    "ce92c6d1af345c645211ad49692b22338d128d974e3b6718c868e02776c873a9".DecodeHex()));

            Client.GetVaultAccounts("ru74fjxlkipzzctorwj4icrj2a", TestData.SesionKey, keychain, http);
        }
示例#16
0
        public void StartNewSession_returns_session_on_ok()
        {
            var http    = MakeJsonHttp(JsonHttpClientTest.SetupGetWithFixture("start-new-session-response"));
            var session = Client.StartNewSession(TestData.ClientInfo, http);

            Assert.That(session.Id, Is.EqualTo(TestData.Session.Id));
            Assert.That(session.KeyFormat, Is.EqualTo(TestData.Session.KeyFormat));
            Assert.That(session.KeyUuid, Is.EqualTo(TestData.Session.KeyUuid));
            Assert.That(session.SrpMethod, Is.EqualTo(TestData.Session.SrpMethod));
            Assert.That(session.KeyMethod, Is.EqualTo(TestData.Session.KeyMethod));
            Assert.That(session.Iterations, Is.EqualTo(TestData.Session.Iterations));
            Assert.That(session.Salt, Is.EqualTo(TestData.Session.Salt));
        }
示例#17
0
        public void GetVaultAccounts_makes_GET_request_to_specific_url()
        {
            var http =
                MakeJsonHttp(
                    JsonHttpClientTest.SetupGetWithFixture("get-vault-accounts-ru74-response"));
            var keychain = new Keychain();

            keychain.Add(new AesKey("x4ouqoqyhcnqojrgubso4hsdga",
                                    "ce92c6d1af345c645211ad49692b22338d128d974e3b6718c868e02776c873a9".DecodeHex()));

            Client.GetVaultAccounts("ru74fjxlkipzzctorwj4icrj2a", TestData.SesionKey, keychain, http);

            JsonHttpClientTest.VerifyGetUrl(http.Http, "1password.com/api/v1/vault");
        }
示例#18
0
        public void VerifySessionKey_works()
        {
            var http = MakeJsonHttp(JsonHttpClientTest.SetupPostWithFixture("verify-key-response"));

            Client.VerifySessionKey(TestData.ClientInfo, TestData.Session, TestData.SesionKey, http);
        }
示例#19
0
 private static JsonHttpClient SetupJsonHttp(string fixture)
 {
     return(new JsonHttpClient(JsonHttpClientTest.SetupPostWithFixture(fixture).Object,
                               Client.GetApiUrl(Client.DefaultDomain)));
 }
示例#20
0
        public void RegisterDevice_works()
        {
            var http = MakeJsonHttp(JsonHttpClientTest.SetupPost("{'success': 1}"));

            Client.RegisterDevice(TestData.ClientInfo, http);
        }
示例#21
0
        public void GetAccountInfo_works()
        {
            var http = MakeJsonHttp(JsonHttpClientTest.SetupGetWithFixture("get-account-info-response"));

            Client.GetAccountInfo(TestData.SesionKey, http);
        }
示例#22
0
        public void GetKeysets_works()
        {
            var http = MakeJsonHttp(JsonHttpClientTest.SetupGetWithFixture("empty-object-response"));

            Client.GetKeysets(TestData.SesionKey, http);
        }
示例#23
0
        public void SignOut_works()
        {
            var http = MakeJsonHttp(JsonHttpClientTest.SetupPut("{'success': 1}"));

            Client.SignOut(http);
        }