-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Validate TXT prefix #1507
Validate TXT prefix #1507
Conversation
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: ruudk The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/assign @njuettner |
6723319
to
dea703c
Compare
If you want I can incorporate your validations into #1483. |
@jgrumboe Thanks I think better for the maintainers to review this separately |
Issues go stale after 90d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
dea703c
to
3b685da
Compare
Rebased the PR because #1483 was merged. |
3b685da
to
e5fce25
Compare
Stale issues rot after 30d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
/remove-lifecycle rotten |
/assign |
/lgtm @tariq1890 and @vinny-sabatini please take a look when you have some time. After you review I'd like to assign this to the external-dns approvers, and see if we can get this merged. Thanks! |
/cc @tariq1890 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the rest of this code change (except the one comment about the error creation) looks good to me.
One thing I am unsure of is if it matters if the txt record starts or ends with .
or -
characters.
Signed-off-by: Ruud Kamphuis <ruudk@users.noreply.github.com>
e5fce25
to
6e19628
Compare
New changes are detected. LGTM label has been removed. |
Applied the requested changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a couple of comments, I am not sure that the check that we are doing is accurate or enough. In case it is not accurate or complete I would rather not having a check.
require.Error(t, err, `invalid TXT prefix provided, expected "[a-z0-9-.]+" got "@invalid#"`) | ||
_, err = NewTXTRegistry(p, "", "@invalid#", "owner", time.Hour) | ||
require.Error(t, err, `invalid TXT suffix provided, expected "[a-z0-9-.]+" got "@invalid#"`) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I add
_, err = NewTXTRegistry(p, "valid....", "", "owner", time.Hour)
require.Error(t, err)
That also looks invalid to me, but the test fails. Are you sure the check that we are doing is fine?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then we need to improve the regex that is used. Any suggestions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
^([a-z0-9]+(-[a-z0-9]+)*)$
maybe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -60,6 +60,26 @@ func testTXTRegistryNew(t *testing.T) { | |||
_, err = NewTXTRegistry(p, "txt", "txt", "owner", time.Hour) | |||
require.Error(t, err) | |||
|
|||
_, err = NewTXTRegistry(p, "@invalid#", "", "owner", time.Hour) | |||
require.Error(t, err, `invalid TXT prefix provided, expected "[a-z0-9-.]+" got "@invalid#"`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This message and the one on like 66 are not accurate, I recommend changing it like:
require.Error(t, err, `invalid TXT prefix provided, expected "[a-z0-9-.]+" got "@invalid#"`) | |
require.Error(t, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are they not accurate? By comparing the error string I make sure that the guard that returns the error works. If I just accept any error, it would make it less good, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because what is happening when you have an error is not that the TXT prefix is invalid, rather than it is expected to be invalid, but there is no error. The string you are providing is only changing the messaging to report, not changing any behavior at all. The default message instead, is correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that this had no follow up, I'm going to close this, to keep a bit of clarity in the PRs that we have to review. Please reopen if you feel you can follow up on this @ruudk . |
To prevent mistakes I think it's good to validate the txt prefix on startup.