Skip to content

Commit

Permalink
Issue 132 add changeset printout (#133)
Browse files Browse the repository at this point in the history
* add text dump functionality

* Add text dump of changeset contents

* Address flake8 errors

* Fix cargo fmt errors

* Generate iterable lists/maps more efficiently

* Fix lint/fmt errors

* StateMgr FIFO expects Changesets

* Address flake8 lint error

* Address flake8 lint error

* fixed up UI unit tests

Co-authored-by: Shawn Dorsch <dorschs@ctc.com>
  • Loading branch information
tparchambault and dorschs57 committed Jun 9, 2021
1 parent dd3aa5e commit 4b3ff18
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -17,6 +17,7 @@ dist
\#*.glade\#
*.glade~
.coverage
.testmondata
.env
*.mo

Expand Down
Binary file removed python/.testmondata
Binary file not shown.
Expand Up @@ -71,13 +71,16 @@ def test_updates_trust_details(widget, mocker):
mocker.patch.object(widget.trustFileDetails, "set_in_databae_view")
mocker.patch.object(widget.trustFileDetails, "set_on_file_system_view")
mocker.patch.object(widget.trustFileDetails, "set_trust_status")
mocker.patch(
"ui.ancillary_trust_database_admin.fs.stat", return_value="stat for foo file"
)
trust = MagicMock(status="T", path="/tmp/foo", size=1, hash="abc")
widget.on_file_selection_change(trust)
widget.trustFileDetails.set_in_databae_view.assert_called_with(
"File: /tmp/foo\nSize: 1\nSHA256: abc"
)
widget.trustFileDetails.set_on_file_system_view.assert_called_with(
"stat: cannot stat '/tmp/foo': No such file or directory\nSHA256: abc"
"stat for foo file\nSHA256: abc"
)
widget.trustFileDetails.set_trust_status.assert_called_with("This file is trusted.")

Expand Down Expand Up @@ -116,9 +119,11 @@ def test_on_neg_confirm_deployment(widget, confirm_dialog):
def test_on_revert_deployment(widget, confirm_dialog, revert_dialog, state):
parent = Gtk.Window()
parent.add(widget.get_content())

with patch("fapolicy_analyzer.System") as mock:
widget.system = mock.return_value
state.add_changeset_q("foo")
mockChangeset = MagicMock()
state.add_changeset_q(mockChangeset)
assert len(state.get_changeset_q()) == 1
widget.on_deployBtn_clicked()
assert len(state.get_changeset_q()) == 1
Expand All @@ -131,9 +136,11 @@ def test_on_revert_deployment(widget, confirm_dialog, revert_dialog, state):
def test_on_neg_revert_deployment(widget, confirm_dialog, revert_dialog, state):
parent = Gtk.Window()
parent.add(widget.get_content())

with patch("fapolicy_analyzer.System") as mock:
widget.system = mock.return_value
state.add_changeset_q("foo")
mockChangeset = MagicMock()
state.add_changeset_q(mockChangeset)
assert len(state.get_changeset_q()) == 1
widget.on_deployBtn_clicked()
assert len(state.get_changeset_q()) == 0
Expand Down
6 changes: 6 additions & 0 deletions python/fapolicy_analyzer/ui/ancillary_trust_database_admin.py
Expand Up @@ -131,6 +131,12 @@ def on_untrustBtn_clicked(self, *args):
self.delete_trusted_files(self.selectedFile)

def on_deployBtn_clicked(self, *args):
# Get list of human-readable undeployed path/operation pairs
listPathActionTuples = stateManager.get_path_action_list()

# TODO: 20210607 tpa Functional verification. Pls leave in until ui
# element integration
print(listPathActionTuples)
parent = self.content.get_toplevel()
confirmDialog = ConfirmDialog(
strings.DEPLOY_ANCILLARY_CONFIRM_DIALOG_TITLE,
Expand Down
5 changes: 5 additions & 0 deletions python/fapolicy_analyzer/ui/state_manager.py
Expand Up @@ -86,6 +86,11 @@ def __update_dirty_queue(self):
self.changeset_queue_updated()
return self.bDirtyQ

def get_path_action_list(self):
# Iterate through the StateManagers Changeset list
# Each changeset contains a dict with at least one Path/Action pair
return [t for e in self.listChangeset for t in e.get_path_action_map().items()]

def add_system_notification(
self, notification: str, notification_type: NotificationType
):
Expand Down
6 changes: 6 additions & 0 deletions python/src/trust.rs
@@ -1,3 +1,5 @@
use std::collections::HashMap;

use pyo3::prelude::*;

use fapolicy_analyzer::api;
Expand Down Expand Up @@ -105,6 +107,10 @@ impl PyChangeset {
pub fn is_empty(&self) -> bool {
self.len() == 0
}

pub fn get_path_action_map(&self) -> HashMap<String, String> {
trust::get_path_action_map(&self.s)
}
}

pub fn init_module(_py: Python, m: &PyModule) -> PyResult<()> {
Expand Down
12 changes: 12 additions & 0 deletions src/trust.rs
Expand Up @@ -158,6 +158,14 @@ impl TrustOp {
}
}

fn to_pair(trust_op: &TrustOp) -> (String, String) {
match trust_op {
TrustOp::Add(path) => (path.to_string(), "Add".to_string()),
TrustOp::Del(path) => (path.to_string(), "Del".to_string()),
TrustOp::Ins(path, _size, _hash) => (path.to_string(), "Ins".to_string()),
}
}

pub enum ChangesetErr {
NotFound,
}
Expand Down Expand Up @@ -199,6 +207,10 @@ impl Changeset {
}
}

pub fn get_path_action_map(cs: &Changeset) -> HashMap<String, String> {
cs.changes.iter().map(to_pair).collect()
}

impl ::std::default::Default for Changeset {
fn default() -> Self {
Self { changes: vec![] }
Expand Down

0 comments on commit 4b3ff18

Please sign in to comment.