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

Added more tests to test_whitelist.py #565

Open
wants to merge 232 commits into
base: develop
Choose a base branch
from

Conversation

Sekhar-Kumar-Dash
Copy link
Contributor

Fixes Issue #564

This pull request adds more tests for whitelist.py

  • My code follows the code style of this project.
  • My change requires changes to the documentation.
  • I have updated the documentation accordingly.
  • All new and existing tests passed.
  • This PR does not contain plagiarized content.
  • The title of my pull request is a short description of the requested changes.

Sekhar-Kumar-Dash and others added 30 commits April 8, 2024 21:17
AlyaGomaa and others added 28 commits May 28, 2024 16:05
…t_flow_alerts_into_smaller_files

Split flow alerts into smaller files
…ct_doh

Alert on DoH and ignore conn without DNS when DoH is detected
Copy link
Collaborator

@AlyaGomaa AlyaGomaa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @Sekhar-Kumar-Dash i added some comments, please don't start resolving them until i push my refactoring for whitelist.py so we can better test large functions. thanksssss



@patch("slips_files.common.parsers.config_parser.ConfigParser.whitelist_path")
def test_read_configuration(mock_config_parser, mock_db):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey @Sekhar-Kumar-Dash here you were patching slips_files.common.parsers.config_parser.ConfigParser only, but in this case, we need to patch the whitelist.path() method, not the class, i fixed it. can you check my previous 3 commits to this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay

),
}
mock_db.is_whitelisted_tranco_domain.return_value = False
assert whitelist.is_whitelisted_attacker(attacker_data) == expected_result
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the second test case, how come example.com is the attacker domain, and the get_all_whitelist.return_value has example.com as a whitelisted domain, and yet the expected return value is false? should be whitelisted right? if there's something wrong with the original is_whitelisted_attacker() function, can you tell me?

),
}
mock_db.is_whitelisted_tranco_domain.return_value = False
assert whitelist.is_whitelisted_victim(victim_data) == expected_result
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this has the same issue as my comment in the above function. how come example.com is not whitelisted by is_whitelisted_victim??

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the there is something wrong with the actual code let's check it

whitelist = ModuleFactory().create_whitelist_obj(mock_db)
mock_db.set_org_info = MagicMock()
actual_result = whitelist.load_org_domains(org)
for domain in expected_result:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can call it parsed_domains instead of actual_result, it is more readable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay

"flow_data, whitelist_data, expected_result",
[
( # testing_is_whitelisted_flow_with_whitelisted_organization_but_ip_or_domain_not_whitelisted
MagicMock(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey you can use spaces as word separators in comments instead of _ :))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's just a mistake I made while typing quickly. Sorry about that.

) = whitelist.read_whitelist()
whitelisted_IPs, whitelisted_domains, whitelisted_orgs, whitelisted_mac = (
whitelist.read_whitelist()
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we can use mock file for testing the read_whitelist function, this is an important one so we probably should have more strict tests for it. for example 2 whitelist test files would be enough, and in these files we can check for expected values, missing columns, missing values in a line, etc. what do you think @Sekhar-Kumar-Dash

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes you are right

],
)
def test_is_whitelisted_flow(
mock_db, flow_data, whitelist_data, expected_result
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i will split is_whitelisted_flow() into smaller functions and will let you know so we can better test it, it's very long now and this test case is testing too many different things at once

@Sekhar-Kumar-Dash
Copy link
Contributor Author

Hello @Sekhar-Kumar-Dash i added some comments, please don't start resolving them until i push my refactoring for whitelist.py so we can better test large functions. thanksssss

Okay

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants