def test_update_keychain_add_multi(self): logger.info(self.getTestHeader('test update keychain add multi')) keychain_file = ospj(self.test_config_dir, 'test-keychain-8.json') added_entries = [{ "uri": "https://foo.bar.com/", "auth_type": "http-basic", "auth_params": { "auth_method": "get", "username": "******", "password": "******" } }, { "uri": "https://foo.bar.com/", "auth_type": "bearer-token", "auth_params": { "token": "bar", "allow_redirects_with_token": "True", "additional_request_headers": { "X-Requested-With": "XMLHttpRequest" } } }] try: keychain = read_keychain(keychain_file, create_default=False) entries = get_auth_entries("https://foo.bar.com/", keychain) self.assertFalse(entries) updated_keychain = update_keychain(added_entries, keychain_file=keychain_file) logger.info("Updated keychain: %s" % json.dumps(updated_keychain)) entries = get_auth_entries("https://foo.bar.com/", updated_keychain) self.assertTrue(len(entries) == 2) except Exception as e: self.fail(bdbag.get_typed_exception(e))
def test_update_keychain_single(self): logger.info(self.getTestHeader('test update keychain single')) keychain_file = ospj(self.test_config_dir, 'test-keychain-8.json') updated_entry = { "uri": "https://raw.githubusercontent.com/", "auth_type": "http-basic", "auth_params": { "auth_method": "get", "username": "******", "password": "******" } } try: updated_keychain = update_keychain(updated_entry, keychain_file=keychain_file) logger.info("Updated keychain: %s" % json.dumps(updated_keychain)) entries = get_auth_entries("https://raw.githubusercontent.com/", updated_keychain) found = False for entry in entries: if entry["auth_type"] == "http-basic": if entry["auth_params"]["username"] == "foo" and entry[ "auth_params"]["password"] == "bar!": found = True break self.assertTrue(found) except Exception as e: self.fail(bdbag.get_typed_exception(e))
def update_bdbag_keychain(self, token=None, host=None, keychain_file=None, allow_redirects=False, delete=False): if (token is None) and (host is None): return keychain_file = keychain_file or bdbkc.DEFAULT_KEYCHAIN_FILE entry = { "uri": self.host_to_url(host), "tag": self.__class__.__name__, "auth_type": "bearer-token", "auth_params": { "token": token, "allow_redirects_with_token": "True" if allow_redirects else "False" } } bdbkc.update_keychain(entry, keychain_file=keychain_file, delete=delete)
def test_update_keychain_del_by_tag(self): logger.info(self.getTestHeader('test update keychain del by tag')) keychain_file = ospj(self.test_config_dir, 'test-keychain-8.json') deleted_entries = {"tag": "unit test"} try: keychain = read_keychain(keychain_file, create_default=False) entries = get_auth_entries("https://raw.githubusercontent.com/", keychain) self.assertTrue(entries) updated_keychain = update_keychain(deleted_entries, keychain_file=keychain_file, delete=True) logger.info("Updated keychain: %s" % json.dumps(updated_keychain)) entries = get_auth_entries("https://raw.githubusercontent.com/", updated_keychain) self.assertFalse(entries) except Exception as e: self.fail(bdbag.get_typed_exception(e))
def test_update_keychain_del_single(self): logger.info(self.getTestHeader('test update keychain del single')) keychain_file = ospj(self.test_config_dir, 'test-keychain-8.json') deleted_entry = { "uri": "ftp://ftp.nist.gov/", "auth_type": "ftp-basic" } try: keychain = read_keychain(keychain_file, create_default=False) entries = get_auth_entries("ftp://ftp.nist.gov/", keychain) self.assertTrue(len(entries) == 1) updated_keychain = update_keychain(deleted_entry, keychain_file=keychain_file, delete=True) logger.info("Updated keychain: %s" % json.dumps(updated_keychain)) entries = get_auth_entries("ftp://ftp.nist.gov/", updated_keychain) self.assertFalse(entries) except Exception as e: self.fail(bdbag.get_typed_exception(e))
def test_update_keychain_multi(self): logger.info(self.getTestHeader('test update keychain multi')) keychain_file = ospj(self.test_config_dir, 'test-keychain-8.json') updated_entries = [{ "uri": "https://raw.githubusercontent.com/", "auth_type": "http-basic", "auth_params": { "auth_method": "get", "username": "******", "password": "******" } }, { "uri": "https://raw.githubusercontent.com/", "auth_type": "bearer-token", "auth_params": { "token": "bar", "allow_redirects_with_token": "True", "additional_request_headers": { "X-Requested-With": "XMLHttpRequest" } } }] try: updated_keychain = update_keychain(updated_entries, keychain_file=keychain_file) logger.info("Updated keychain: %s" % json.dumps(updated_keychain)) entries = get_auth_entries("https://raw.githubusercontent.com/", updated_keychain) found1 = found2 = False for entry in entries: if entry["auth_type"] == "http-basic": if entry["auth_params"]["password"] == "bar!": found1 = True if entry["auth_type"] == "bearer-token": if entry["auth_params"][ "allow_redirects_with_token"] == "True": found2 = True self.assertTrue(found1 and found2) except Exception as e: self.fail(bdbag.get_typed_exception(e))
def test_update_keychain_invalid_params(self): logger.info(self.getTestHeader('test update keychain invalid params')) keychain_file = ospj(self.test_config_dir, 'test-keychain-8.json') deleted_entries = [{ "uri": "https://raw.githubusercontent.com/", }, { "auth_type": "bearer-token" }, { "uri": "ftp://ftp.nist.gov/", "tag": "invalid" }] try: keychain = read_keychain(keychain_file, create_default=False) entries = get_auth_entries("https://raw.githubusercontent.com/", keychain) self.assertTrue(entries) updated_keychain = update_keychain(deleted_entries, keychain_file=keychain_file, delete=True) logger.info("Updated keychain: %s" % json.dumps(updated_keychain)) self.assertTrue(len(updated_keychain) == 3) except Exception as e: self.fail(bdbag.get_typed_exception(e))
def test_update_keychain_del_multi(self): logger.info(self.getTestHeader('test update keychain del multi')) keychain_file = ospj(self.test_config_dir, 'test-keychain-8.json') deleted_entries = [{ "uri": "https://raw.githubusercontent.com/", "auth_type": "http-basic" }, { "uri": "https://raw.githubusercontent.com/", "auth_type": "bearer-token" }] try: keychain = read_keychain(keychain_file, create_default=False) entries = get_auth_entries("https://raw.githubusercontent.com/", keychain) self.assertTrue(entries) updated_keychain = update_keychain(deleted_entries, keychain_file=keychain_file, delete=True) logger.info("Updated keychain: %s" % json.dumps(updated_keychain)) entries = get_auth_entries("https://raw.githubusercontent.com/", updated_keychain) self.assertFalse(entries) except Exception as e: self.fail(bdbag.get_typed_exception(e))
def test_update_keychain_add_single(self): logger.info(self.getTestHeader('test update keychain add single')) keychain_file = ospj(self.test_config_dir, 'test-keychain-8.json') added_entry = { "uri": "https://foo.bar.com/", "auth_type": "http-basic", "auth_params": { "auth_method": "get", "username": "******", "password": "******" } } try: keychain = read_keychain(keychain_file, create_default=False) entries = get_auth_entries("https://foo.bar.com/", keychain) self.assertFalse(entries) updated_keychain = update_keychain(added_entry, keychain_file=keychain_file) logger.info("Updated keychain: %s" % json.dumps(updated_keychain)) entries = get_auth_entries("https://foo.bar.com/", updated_keychain) self.assertTrue(len(entries) == 1) except Exception as e: self.fail(bdbag.get_typed_exception(e))