예제 #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);
        }