-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[management, proxy] Add require_subdomain capability for proxy clusters #5628
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 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2910e7e
Add require_subdomain capability for proxy clusters
lixmal 81f2e63
Fix missing ClusterRequireSubdomain on proxy integration test mock
lixmal ffa26ab
Prefer longest custom domain match and validate subdomain on every up…
lixmal f759ea0
Extract transaction body from persistServiceUpdate to reduce cognitiv…
lixmal 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
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
130 changes: 130 additions & 0 deletions
130
management/internals/modules/reverseproxy/domain/manager/domain_test.go
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 |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| package manager | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
|
|
||
| "github.com/netbirdio/netbird/management/internals/modules/reverseproxy/domain" | ||
| ) | ||
|
|
||
| func TestExtractClusterFromFreeDomain(t *testing.T) { | ||
| clusters := []string{"eu1.proxy.netbird.io", "us1.proxy.netbird.io"} | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| domain string | ||
| wantOK bool | ||
| wantVal string | ||
| }{ | ||
| { | ||
| name: "subdomain of cluster matches", | ||
| domain: "myapp.eu1.proxy.netbird.io", | ||
| wantOK: true, | ||
| wantVal: "eu1.proxy.netbird.io", | ||
| }, | ||
| { | ||
| name: "deep subdomain of cluster matches", | ||
| domain: "foo.bar.eu1.proxy.netbird.io", | ||
| wantOK: true, | ||
| wantVal: "eu1.proxy.netbird.io", | ||
| }, | ||
| { | ||
| name: "bare cluster domain matches", | ||
| domain: "eu1.proxy.netbird.io", | ||
| wantOK: true, | ||
| wantVal: "eu1.proxy.netbird.io", | ||
| }, | ||
| { | ||
| name: "unrelated domain does not match", | ||
| domain: "example.com", | ||
| wantOK: false, | ||
| }, | ||
| { | ||
| name: "partial suffix does not match", | ||
| domain: "fakeu1.proxy.netbird.io", | ||
| wantOK: false, | ||
| }, | ||
| { | ||
| name: "second cluster matches", | ||
| domain: "app.us1.proxy.netbird.io", | ||
| wantOK: true, | ||
| wantVal: "us1.proxy.netbird.io", | ||
| }, | ||
| } | ||
|
|
||
| for _, tc := range tests { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| cluster, ok := ExtractClusterFromFreeDomain(tc.domain, clusters) | ||
| assert.Equal(t, tc.wantOK, ok) | ||
| if ok { | ||
| assert.Equal(t, tc.wantVal, cluster) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestExtractClusterFromCustomDomains(t *testing.T) { | ||
| customDomains := []*domain.Domain{ | ||
| {Domain: "example.com", TargetCluster: "eu1.proxy.netbird.io"}, | ||
| {Domain: "proxy.corp.io", TargetCluster: "us1.proxy.netbird.io"}, | ||
| } | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| domain string | ||
| wantOK bool | ||
| wantVal string | ||
| }{ | ||
| { | ||
| name: "subdomain of custom domain matches", | ||
| domain: "app.example.com", | ||
| wantOK: true, | ||
| wantVal: "eu1.proxy.netbird.io", | ||
| }, | ||
| { | ||
| name: "bare custom domain matches", | ||
| domain: "example.com", | ||
| wantOK: true, | ||
| wantVal: "eu1.proxy.netbird.io", | ||
| }, | ||
| { | ||
| name: "deep subdomain of custom domain matches", | ||
| domain: "a.b.example.com", | ||
| wantOK: true, | ||
| wantVal: "eu1.proxy.netbird.io", | ||
| }, | ||
| { | ||
| name: "subdomain of multi-level custom domain matches", | ||
| domain: "app.proxy.corp.io", | ||
| wantOK: true, | ||
| wantVal: "us1.proxy.netbird.io", | ||
| }, | ||
| { | ||
| name: "bare multi-level custom domain matches", | ||
| domain: "proxy.corp.io", | ||
| wantOK: true, | ||
| wantVal: "us1.proxy.netbird.io", | ||
| }, | ||
| { | ||
| name: "unrelated domain does not match", | ||
| domain: "other.com", | ||
| wantOK: false, | ||
| }, | ||
| { | ||
| name: "partial suffix does not match custom domain", | ||
| domain: "fakeexample.com", | ||
| wantOK: false, | ||
| }, | ||
| } | ||
|
|
||
| for _, tc := range tests { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| cluster, ok := extractClusterFromCustomDomains(tc.domain, customDomains) | ||
| assert.Equal(t, tc.wantOK, ok) | ||
| if ok { | ||
| assert.Equal(t, tc.wantVal, cluster) | ||
| } | ||
| }) | ||
| } | ||
| } |
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
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
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
14 changes: 14 additions & 0 deletions
14
management/internals/modules/reverseproxy/proxy/manager_mock.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.