Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: permissions on xcall connection #689

Merged
merged 3 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ pub enum ExecuteMsg {
},
}


#[cw_serde]
pub struct ConfigResponse {
pub channel_id: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl<'a> CwIbcConnection<'a> {
});
}

self.ensure_owner(store, &info)?;
self.ensure_admin(store, info.sender)?;

self.admin()
.update(store, |mut current_admin| -> Result<_, ContractError> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ use crate::{
XCALL_HANDLE_ERROR_REPLY_ID, XCALL_HANDLE_MESSAGE_REPLY_ID,
},
types::{
channel_config::ChannelConfig, config::Config, connection_config::ConnectionConfig,
config_response::to_config_response,
message::Message, LOG_PREFIX,
channel_config::ChannelConfig, config::Config, config_response::to_config_response,
connection_config::ConnectionConfig, message::Message, LOG_PREFIX,
},
};

Expand Down Expand Up @@ -107,7 +106,7 @@ impl<'a> CwIbcConnection<'a> {
self.send_message(deps, info, env, to, sn, msg)
}
ExecuteMsg::SetXCallHost { address } => {
self.ensure_owner(deps.as_ref().storage, &info)?;
self.ensure_admin(deps.as_ref().storage, info.sender)?;
let validated_address =
CwIbcConnection::validate_address(deps.api, address.as_str())?;
self.set_xcall_host(deps.storage, validated_address)?;
Expand All @@ -120,7 +119,7 @@ impl<'a> CwIbcConnection<'a> {
client_id,
timeout_height,
} => {
self.ensure_owner(deps.as_ref().storage, &info)?;
self.ensure_admin(deps.as_ref().storage, info.sender)?;
self.configure_connection(
deps.storage,
connection_id,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use cw_common::xcall_connection_msg::ConfigResponse;

use crate::types::channel_config::ChannelConfig;
use crate::state::IbcConfig;
use crate::types::channel_config::ChannelConfig;

pub fn to_config_response(ibc_config: IbcConfig, channel_config: ChannelConfig) -> ConfigResponse {
ConfigResponse {
Expand All @@ -12,4 +12,4 @@ pub fn to_config_response(ibc_config: IbcConfig, channel_config: ChannelConfig)
light_client_id: channel_config.client_id,
timeout_height: channel_config.timeout_height.clone(),
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ pub mod storage_keys;
pub use common::rlp;

pub mod channel_config;
pub mod config_response;
pub mod config;
pub mod config_response;
pub mod connection_config;
pub mod message;
pub mod network_fees;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fn add_admin() {
}

#[test]
#[should_panic(expected = "Unauthorized")]
#[should_panic(expected = "OnlyAdmin")]
fn update_admin_unauthorzied() {
let mut mock_deps = deps();

Expand Down Expand Up @@ -113,6 +113,8 @@ fn update_admin() {

assert_eq!(result, admin_one().to_string());

let mock_info = create_mock_info(&admin_one().to_string(), "umlg", 2000);

contract
.update_admin(
mock_deps.as_mut().storage,
Expand Down Expand Up @@ -151,6 +153,8 @@ fn update_existing_admin() {

assert_eq!(result, admin_one().to_string());

let mock_info = create_mock_info(&admin_one().to_string(), "umlg", 2000);

contract
.update_admin(
mock_deps.as_mut().storage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ fn success_on_setting_timeout_height() {
}

#[test]
#[should_panic(expected = "Unauthorized")]
#[should_panic(expected = "OnlyAdmin")]
fn fails_on_configure_connection_unauthorized() {
let mut deps = deps();

Expand Down
Loading