-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[proxy] feature: bring your own proxy #5627
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
Open
crn4
wants to merge
16
commits into
main
Choose a base branch
from
feat/byod-proxy
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
26ba03f
[proxy] feature: bring your own proxy
crn4 da57b0f
rename byod to byop
crn4 177171e
change api
crn4 0b5380a
review comments
crn4 9dd76b5
merge main
crn4 38fd73f
merge main
crn4 94149a9
linter
crn4 4fdc39c
review comments
crn4 de3cb06
added proxy id to cluster api response
crn4 e625211
Merge remote-tracking branch 'origin/main' into feat/byod-proxy
crn4 8fe2b5e
removed condition on 1 yop per account
crn4 7c4011d
remove withContext from all sql calls
crn4 e6a663b
merge main
crn4 4f0d6ef
delete cluster + fix front issues
crn4 f78bc61
test fix
crn4 49f170c
fixed issue with byop shared accross accounts
crn4 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
110 changes: 110 additions & 0 deletions
110
management/internals/modules/reverseproxy/domain/manager/manager_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,110 @@ | ||
| package manager | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| type mockProxyManager struct { | ||
| getActiveClusterAddressesFunc func(ctx context.Context) ([]string, error) | ||
| getActiveClusterAddressesForAccountFunc func(ctx context.Context, accountID string) ([]string, error) | ||
| } | ||
|
|
||
| func (m *mockProxyManager) GetActiveClusterAddresses(ctx context.Context) ([]string, error) { | ||
| if m.getActiveClusterAddressesFunc != nil { | ||
| return m.getActiveClusterAddressesFunc(ctx) | ||
| } | ||
| return nil, nil | ||
| } | ||
|
|
||
| func (m *mockProxyManager) GetActiveClusterAddressesForAccount(ctx context.Context, accountID string) ([]string, error) { | ||
| if m.getActiveClusterAddressesForAccountFunc != nil { | ||
| return m.getActiveClusterAddressesForAccountFunc(ctx, accountID) | ||
| } | ||
| return nil, nil | ||
| } | ||
|
|
||
| func (m *mockProxyManager) ClusterSupportsCustomPorts(_ context.Context, _ string) *bool { | ||
| return nil | ||
| } | ||
|
|
||
| func (m *mockProxyManager) ClusterRequireSubdomain(_ context.Context, _ string) *bool { | ||
| return nil | ||
| } | ||
|
|
||
| func (m *mockProxyManager) ClusterSupportsCrowdSec(_ context.Context, _ string) *bool { | ||
| return nil | ||
| } | ||
|
|
||
| func TestGetClusterAllowList_BYOPProxy(t *testing.T) { | ||
| pm := &mockProxyManager{ | ||
| getActiveClusterAddressesForAccountFunc: func(_ context.Context, accID string) ([]string, error) { | ||
| assert.Equal(t, "acc-123", accID) | ||
| return []string{"byop.example.com"}, nil | ||
| }, | ||
| getActiveClusterAddressesFunc: func(_ context.Context) ([]string, error) { | ||
| t.Fatal("should not call GetActiveClusterAddresses when BYOP addresses exist") | ||
| return nil, nil | ||
| }, | ||
| } | ||
|
|
||
| mgr := Manager{proxyManager: pm} | ||
| result, err := mgr.getClusterAllowList(context.Background(), "acc-123") | ||
| require.NoError(t, err) | ||
| assert.Equal(t, []string{"byop.example.com"}, result) | ||
| } | ||
|
|
||
| func TestGetClusterAllowList_NoBYOP_FallbackToShared(t *testing.T) { | ||
| pm := &mockProxyManager{ | ||
| getActiveClusterAddressesForAccountFunc: func(_ context.Context, _ string) ([]string, error) { | ||
| return nil, nil | ||
| }, | ||
| getActiveClusterAddressesFunc: func(_ context.Context) ([]string, error) { | ||
| return []string{"eu.proxy.netbird.io", "us.proxy.netbird.io"}, nil | ||
| }, | ||
| } | ||
|
|
||
| mgr := Manager{proxyManager: pm} | ||
| result, err := mgr.getClusterAllowList(context.Background(), "acc-123") | ||
| require.NoError(t, err) | ||
| assert.Equal(t, []string{"eu.proxy.netbird.io", "us.proxy.netbird.io"}, result) | ||
| } | ||
|
|
||
| func TestGetClusterAllowList_BYOPError_ReturnsError(t *testing.T) { | ||
| pm := &mockProxyManager{ | ||
| getActiveClusterAddressesForAccountFunc: func(_ context.Context, _ string) ([]string, error) { | ||
| return nil, errors.New("db error") | ||
| }, | ||
| getActiveClusterAddressesFunc: func(_ context.Context) ([]string, error) { | ||
| t.Fatal("should not call GetActiveClusterAddresses when BYOP lookup fails") | ||
| return nil, nil | ||
| }, | ||
| } | ||
|
|
||
| mgr := Manager{proxyManager: pm} | ||
| result, err := mgr.getClusterAllowList(context.Background(), "acc-123") | ||
| require.Error(t, err) | ||
| assert.Nil(t, result) | ||
| assert.Contains(t, err.Error(), "BYOP cluster addresses") | ||
| } | ||
|
|
||
| func TestGetClusterAllowList_BYOPEmptySlice_FallbackToShared(t *testing.T) { | ||
| pm := &mockProxyManager{ | ||
| getActiveClusterAddressesForAccountFunc: func(_ context.Context, _ string) ([]string, error) { | ||
| return []string{}, nil | ||
| }, | ||
| getActiveClusterAddressesFunc: func(_ context.Context) ([]string, error) { | ||
| return []string{"eu.proxy.netbird.io"}, nil | ||
| }, | ||
| } | ||
|
|
||
| mgr := Manager{proxyManager: pm} | ||
| result, err := mgr.getClusterAllowList(context.Background(), "acc-123") | ||
| require.NoError(t, err) | ||
| assert.Equal(t, []string{"eu.proxy.netbird.io"}, result) | ||
| } | ||
|
|
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.