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

implement tri-state verification in FTP detector #1604

Merged
merged 8 commits into from
Aug 9, 2023
Merged

Conversation

rosecodym
Copy link
Collaborator

@rosecodym rosecodym commented Aug 3, 2023

This PR implements tri-state verification in the FTP detector. The verification timeout was made injectable to support a new test case.

The dogfood/Github action detection of "new" secrets is just picking up new test cases that use the existing test FTP secrets, which are already cleartext elsewhere in the codebase. (They're publicly available.)

@rosecodym rosecodym requested review from a team August 3, 2023 19:45
Copy link
Collaborator

@mcastorina mcastorina left a comment

Choose a reason for hiding this comment

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

Very nice seeing the GH action proving the test is correct 🤣

Comment on lines +109 to +110
ftpErr := &textproto.Error{}
return errors.As(e, &ftpErr) && ftpErr.Code == ftpNotLoggedIn
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is cool

Comment on lines -51 to +54
Redacted: "ftp://dlpuser:*************************@ftp.dlptest.com",
Redacted: "ftp://dlpuser:********@ftp.dlptest.com",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Curious why some of the tests were adjusted? Did our redaction code update?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i guess so? they were failing on main and i didn't think that figuring out why was worth it

Comment on lines 136 to 146
for i := range got {
got[i].Raw = nil

if (got[i].VerificationError != nil) != tt.wantVerificationErr {
t.Fatalf("wantVerificationError = %v, verification error = %v", tt.wantVerificationErr, got[i].VerificationError)
}
}
if diff := pretty.Compare(got, tt.want); diff != "" {
t.Errorf("URI.FromData() %s diff: (-got +want)\n%s", tt.name, diff)
opts := cmpopts.IgnoreFields(detectors.Result{}, "VerificationError")
if diff := cmp.Diff(got, tt.want, opts); diff != "" {
t.Errorf("FTP.FromData() %s diff: (-got +want)\n%s", tt.name, diff)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit / question: Could we add "Raw" to the cmpopts.IgnoreFields and remove setting it to nil on line 137? If so, we could convert that loop into iterating over values also.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

good thought moving Raw into the ignorelist, but i don't follow the second part of your suggestion

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 the only reason we were iterating over the indices was to clear out the Raw value in the object, so now that Raw is being ignored we don't need to do that and could update the loop to be:

for _, gotResult := range got {
    if (gotResult.Verification != nil) != tt.wantVerificationErr {
        // ...
    }
}

Copy link
Collaborator Author

@rosecodym rosecodym Aug 7, 2023

Choose a reason for hiding this comment

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

oh, no, it's dumber than that. the root problem is that we know when we want to see a verification error, but we don't always know the exact shape of the error, so there's a top-level "is there an error" flag. but verification errors are per result, not per overall chunk flow, so we loop through and check the expected flag against each individual result object.

there's probably a better way to do it, though - i haven't thought about it too hard.

@rosecodym rosecodym merged commit e5aeb21 into main Aug 9, 2023
8 of 9 checks passed
@rosecodym rosecodym deleted the tri-state-ftp branch August 9, 2023 13:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants