From 627b8a8414b92eaaee666b79f9bb9ae7e7578f89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Sun, 11 Dec 2016 17:51:34 +0100 Subject: [PATCH] Changing default policy --- ethcore/src/account_provider/mod.rs | 11 +++++++++-- ethcore/src/account_provider/stores.rs | 4 ++-- rpc/src/v1/tests/mocked/eth.rs | 3 ++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/ethcore/src/account_provider/mod.rs b/ethcore/src/account_provider/mod.rs index 72a546b1f..9177fe0be 100644 --- a/ethcore/src/account_provider/mod.rs +++ b/ethcore/src/account_provider/mod.rs @@ -418,6 +418,8 @@ mod tests { // given let ap = AccountProvider::transient_provider(); let app = "app1".to_owned(); + // set `AllAccounts` policy + ap.set_new_dapps_whitelist(None).unwrap(); // when ap.set_dapps_addresses(app.clone(), vec![1.into(), 2.into()]).unwrap(); @@ -431,10 +433,15 @@ mod tests { // given let ap = AccountProvider::transient_provider(); let address = ap.new_account("test").unwrap(); - // Default policy should be to return all + + // Default policy should be to return nothing + assert_eq!(ap.dapps_addresses("app1".into()).unwrap(), vec![]); + + // change to all + ap.set_new_dapps_whitelist(None).unwrap(); assert_eq!(ap.dapps_addresses("app1".into()).unwrap(), vec![address]); - // change policy + // change to a whitelist ap.set_new_dapps_whitelist(Some(vec![1.into()])).unwrap(); assert_eq!(ap.dapps_addresses("app1".into()).unwrap(), vec![1.into()]); } diff --git a/ethcore/src/account_provider/stores.rs b/ethcore/src/account_provider/stores.rs index 69cf29468..f1f98e2cb 100644 --- a/ethcore/src/account_provider/stores.rs +++ b/ethcore/src/account_provider/stores.rs @@ -175,7 +175,7 @@ impl DappsSettingsStore { /// Returns current new dapps policy pub fn policy(&self) -> NewDappsPolicy { - self.policy.get("default").cloned().unwrap_or(NewDappsPolicy::AllAccounts) + self.policy.get("default").cloned().unwrap_or(NewDappsPolicy::Whitelist(vec![])) } /// Returns recent dapps (in order of last request) @@ -354,7 +354,7 @@ mod tests { let path = temp.as_str().to_owned(); let mut store = DappsSettingsStore::new(path.clone()); // Test default policy - assert_eq!(store.policy(), NewDappsPolicy::AllAccounts); + assert_eq!(store.policy(), NewDappsPolicy::Whitelist(vec![])); // when store.set_policy(NewDappsPolicy::Whitelist(vec![1.into(), 2.into()])); diff --git a/rpc/src/v1/tests/mocked/eth.rs b/rpc/src/v1/tests/mocked/eth.rs index aa60aeb2e..36eb7eb3b 100644 --- a/rpc/src/v1/tests/mocked/eth.rs +++ b/rpc/src/v1/tests/mocked/eth.rs @@ -355,8 +355,9 @@ fn rpc_eth_gas_price() { fn rpc_eth_accounts() { let tester = EthTester::default(); let address = tester.accounts_provider.new_account("").unwrap(); + tester.accounts_provider.set_new_dapps_whitelist(None).unwrap(); - // with default policy it should return the account + // with current policy it should return the account let request = r#"{"jsonrpc": "2.0", "method": "eth_accounts", "params": [], "id": 1}"#; let response = r#"{"jsonrpc":"2.0","result":[""#.to_owned() + &format!("0x{:?}", address) + r#""],"id":1}"#; assert_eq!(tester.io.handle_request_sync(request), Some(response.to_owned()));