-
Notifications
You must be signed in to change notification settings - Fork 4.5k
xds: add unit tests for HandshakeInfo.Equal
#7638
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ce5843a
Adding unit test case for HandShakeInfo.Equal
janardhankrishna-sai 69ff9ed
Updating TestEqual by changing struct name, removing id field from st…
janardhankrishna-sai dc9b90a
Updating TestEqual by changing struct name, removing id field from st…
janardhankrishna-sai d430e6e
Combining inline conditional check
janardhankrishna-sai 4bb44b7
Removing different root providers, identity providers conditions in test
janardhankrishna-sai 60d0760
Adding 2 new test cases and passing the HanshakeInfo as a pointer type
janardhankrishna-sai 3a63bdb
Updating same providers, different SAN matchers case
janardhankrishna-sai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,9 +25,14 @@ import ( | |
"regexp" | ||
"testing" | ||
|
||
"google.golang.org/grpc/credentials/tls/certprovider" | ||
"google.golang.org/grpc/internal/xds/matcher" | ||
) | ||
|
||
type testCertProvider struct { | ||
certprovider.Provider | ||
} | ||
|
||
func TestDNSMatch(t *testing.T) { | ||
tests := []struct { | ||
desc string | ||
|
@@ -300,3 +305,88 @@ func TestMatchingSANExists_Success(t *testing.T) { | |
func newStringP(s string) *string { | ||
return &s | ||
} | ||
|
||
func TestEqual(t *testing.T) { | ||
tests := []struct { | ||
desc string | ||
hi1 *HandshakeInfo | ||
hi2 *HandshakeInfo | ||
wantMatch bool | ||
}{ | ||
{ | ||
desc: "both HandshakeInfo are nil", | ||
hi1: nil, | ||
hi2: nil, | ||
wantMatch: true, | ||
}, | ||
{ | ||
desc: "one HandshakeInfo is nil", | ||
hi1: nil, | ||
hi2: NewHandshakeInfo(&testCertProvider{}, nil, nil, false), | ||
wantMatch: false, | ||
}, | ||
{ | ||
desc: "different root providers", | ||
hi1: NewHandshakeInfo(&testCertProvider{}, nil, nil, false), | ||
hi2: NewHandshakeInfo(&testCertProvider{}, nil, nil, false), | ||
wantMatch: false, | ||
}, | ||
{ | ||
desc: "same providers, same SAN matchers", | ||
hi1: NewHandshakeInfo(testCertProvider{}, testCertProvider{}, []matcher.StringMatcher{ | ||
matcher.StringMatcherForTesting(newStringP("foo.com"), nil, nil, nil, nil, false), | ||
}, false), | ||
hi2: NewHandshakeInfo(testCertProvider{}, testCertProvider{}, []matcher.StringMatcher{ | ||
matcher.StringMatcherForTesting(newStringP("foo.com"), nil, nil, nil, nil, false), | ||
}, false), | ||
wantMatch: true, | ||
}, | ||
{ | ||
desc: "same providers, different SAN matchers", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test case seems to be subset of the next one. So, we can remove this test case. |
||
hi1: NewHandshakeInfo(testCertProvider{}, testCertProvider{}, []matcher.StringMatcher{ | ||
matcher.StringMatcherForTesting(newStringP("foo.com"), nil, nil, nil, nil, false), | ||
}, false), | ||
hi2: NewHandshakeInfo(testCertProvider{}, testCertProvider{}, []matcher.StringMatcher{ | ||
matcher.StringMatcherForTesting(newStringP("bar.com"), nil, nil, nil, nil, false), | ||
}, false), | ||
wantMatch: false, | ||
}, | ||
{ | ||
desc: "same SAN matchers with different content", | ||
hi1: NewHandshakeInfo(&testCertProvider{}, &testCertProvider{}, []matcher.StringMatcher{ | ||
matcher.StringMatcherForTesting(newStringP("foo.com"), nil, nil, nil, nil, false), | ||
}, false), | ||
hi2: NewHandshakeInfo(&testCertProvider{}, &testCertProvider{}, []matcher.StringMatcher{ | ||
matcher.StringMatcherForTesting(newStringP("foo.com"), nil, nil, nil, nil, false), | ||
matcher.StringMatcherForTesting(newStringP("bar.com"), nil, nil, nil, nil, false), | ||
}, false), | ||
wantMatch: false, | ||
}, | ||
{ | ||
desc: "different requireClientCert flags", | ||
hi1: NewHandshakeInfo(&testCertProvider{}, &testCertProvider{}, nil, true), | ||
hi2: NewHandshakeInfo(&testCertProvider{}, &testCertProvider{}, nil, false), | ||
wantMatch: false, | ||
}, | ||
{ | ||
desc: "same identity provider, different root provider", | ||
hi1: NewHandshakeInfo(&testCertProvider{}, testCertProvider{}, nil, false), | ||
hi2: NewHandshakeInfo(&testCertProvider{}, testCertProvider{}, nil, false), | ||
wantMatch: false, | ||
}, | ||
{ | ||
desc: "different identity provider, same root provider", | ||
hi1: NewHandshakeInfo(testCertProvider{}, &testCertProvider{}, nil, false), | ||
hi2: NewHandshakeInfo(testCertProvider{}, &testCertProvider{}, nil, false), | ||
wantMatch: false, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.desc, func(t *testing.T) { | ||
if gotMatch := test.hi1.Equal(test.hi2); gotMatch != test.wantMatch { | ||
t.Errorf("hi1.Equal(hi2) = %v; wantMatch %v", gotMatch, test.wantMatch) | ||
} | ||
}) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.