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

reject if namespace contains string mismatched with env #232

Merged
merged 14 commits into from
Nov 13, 2024
Merged

Conversation

charlienegri
Copy link
Contributor

@charlienegri charlienegri commented Sep 27, 2024

Summary: if the namespace already contains a string mismatched with the env string, file should be rejected

Related issue:
#228

Suggested reviewer(s):

Reviewer checklist:

  • The headers of all files contain a reference to the repository license
  • 100% test coverage of new code - meaning:
    • The overall test coverage increased or remained the same as before
    • Every function is accompanied with a test suite
    • Tests are both positive (testing that the function work as intended with valid data) and negative (testing that the function behaves as expected with invalid data, e.g., that correct exceptions are thrown)
    • Functions with optional arguments have separate tests for all options
  • Examples are supported by doctests
  • All tests are passing
  • All names (e.g., files, classes, functions, variables) are explicit
  • Documentation (as docstrings) is complete and understandable

The checklist is based on the S-ENDA conventions and definition of done (see General Conventions). The above points are not necessarily relevant to all contributions. In that case, please add a short explanation to help the reviewer.

@charlienegri charlienegri marked this pull request as ready for review September 30, 2024 12:59
@mortenwh
Copy link
Collaborator

@charlienegri - can you add the suggested tests?

@charlienegri
Copy link
Contributor Author

charlienegri commented Oct 18, 2024

@charlienegri - can you add the suggested tests?

so to clarify: I added the file tests/files/api/staging.xml to test the mismatch between env and namespace in testApiWorker_NamespaceRejectedIfWrongEnv, which your added lines break, do you want another test with a similar dev.xml files containing no.met.dev passed as passFile and where we test that trying to validate that in a production env fails?
passWorker._conf.env_string is supposed to be the environment discriminating string

@mortenwh
Copy link
Collaborator

do you want another test with a similar dev.xml files containing no.met.dev passed as passFile and where we test that trying to validate that in a production env fails? passWorker._conf.env_string is supposed to be the environment discriminating string

As mentioned in #232 - we must test that when the env is dev, we accept both no.met and no.met.dev namespaces, and similar for staging. In prod, we should only accept no.met. This is what needs to be tested, and the added lines are a start.

@charlienegri
Copy link
Contributor Author

charlienegri commented Oct 18, 2024

do you want another test with a similar dev.xml files containing no.met.dev passed as passFile and where we test that trying to validate that in a production env fails? passWorker._conf.env_string is supposed to be the environment discriminating string

As mentioned in #232 - we must test that when the env is dev, we accept both no.met and no.met.dev namespaces, and similar for staging. In prod, we should only accept no.met. This is what needs to be tested, and the added lines are a start.

I have now split the test in dev/staging, added another file to the tests batch, to test a .dev namespace
(it cannot be tested with passWorker._conf.env_string = "no.met.dev", that is supposed to be just the env string read from the config)
the fact that no.met would be accepted in dev and staging env is beyond the scope if this PR, isn't that covered by testApiWorker_NamespaceReplacement basically?

@mortenwh
Copy link
Collaborator

I have now split the test in dev/staging, added another file to the tests batch, to test a .dev namespace (it cannot be tested with passWorker._conf.env_string = "no.met.dev", that is supposed to be just the env string read from the config) the fact that no.met would be accepted in dev and staging env is beyond the scope if this PR, isn't that covered by testApiWorker_NamespaceReplacement basically?

No, not really. It should be explicit.

tests/test_api/test_worker.py Outdated Show resolved Hide resolved
@charlienegri
Copy link
Contributor Author

charlienegri commented Oct 18, 2024

I have now split the test in dev/staging, added another file to the tests batch, to test a .dev namespace (it cannot be tested with passWorker._conf.env_string = "no.met.dev", that is supposed to be just the env string read from the config) the fact that no.met would be accepted in dev and staging env is beyond the scope if this PR, isn't that covered by testApiWorker_NamespaceReplacement basically?

No, not really. It should be explicit.

in testApiWorker_NamespaceReplacement we test that a namespace test.no is accepted in the environment yolo and ends up being test.no.yolo, you want to add explicitly the cases that no.met is accepted in dev/staging and ends up being no.met.dev/no.met.staging?

@@ -104,48 +100,60 @@ def validate(self, data):
if not valid:
return valid, msg, data

if (".dev" in self._namespace and self._conf.env_string != "dev") or (
Copy link
Collaborator

Choose a reason for hiding this comment

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

why not just check

Suggested change
if (".dev" in self._namespace and self._conf.env_string != "dev") or (
if (self._conf.env_string not in self._namespace) or (

and so on? Does it fail for prod then?

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

What about this?

Suggested change
if (".dev" in self._namespace and self._conf.env_string != "dev") or (
if self._conf.env_string != "" and self._conf.env_string not in self._namespace:

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see that this will also be wrong. The point is that I prefer to avoid hardcoding "dev" and "staging"...

tests/test_api/test_worker.py Outdated Show resolved Hide resolved
dmci/api/worker.py Show resolved Hide resolved
@mortenwh mortenwh merged commit 012da77 into main Nov 13, 2024
5 checks passed
@mortenwh mortenwh deleted the issue_228 branch November 13, 2024 13:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants