-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
config: loosen up BaseDomain and ServerURL checks #2248
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| package types | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "os" | ||
| "path/filepath" | ||
| "testing" | ||
|
|
@@ -139,7 +140,7 @@ func TestReadConfig(t *testing.T) { | |
| return LoadServerConfig() | ||
| }, | ||
| want: nil, | ||
| wantErr: "server_url cannot contain the base_domain, this will cause the headscale server and embedded DERP to become unreachable from the Tailscale node.", | ||
| wantErr: "server_url cannot be a suffix of the base_domain, this will cause the headscale server and embedded DERP to become unreachable from the Tailscale node.", | ||
| }, | ||
| { | ||
| name: "base-domain-not-in-server-url", | ||
|
|
@@ -333,3 +334,59 @@ tls_letsencrypt_challenge_type: TLS-ALPN-01 | |
| err = LoadConfig(tmpDir, false) | ||
| assert.NoError(t, err) | ||
| } | ||
|
|
||
| // OK | ||
| // server_url: headscale.com, base: clients.headscale.com | ||
| // server_url: headscale.com, base: headscale.net | ||
|
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. It is said elsewhere that server url must not be a suffix of the base_domain. To me, server is a suffix of base here -- yes, additionally they are equal. Perhaps the wording using "suffix" needs to be adjusted?
Collaborator
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. you are write, it should probably be reformulated since we allow different domains, open to proposals.
Contributor
Author
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. See updated error message. I think the new one is more intuitive, see if you like it better |
||
| // | ||
| // NOT OK | ||
| // server_url: server.headscale.com, base: headscale.com | ||
| func TestSafeServerURL(t *testing.T) { | ||
| tests := []struct { | ||
| serverURL, baseDomain, | ||
| wantErr string | ||
| }{ | ||
| { | ||
|
motiejus marked this conversation as resolved.
|
||
| serverURL: "https://example.com", | ||
| baseDomain: "example.org", | ||
| }, | ||
| { | ||
| serverURL: "https://headscale.com", | ||
| baseDomain: "headscale.com", | ||
| }, | ||
| { | ||
| serverURL: "https://headscale.com", | ||
| baseDomain: "clients.headscale.com", | ||
| }, | ||
| { | ||
| serverURL: "https://headscale.com", | ||
| baseDomain: "clients.subdomain.headscale.com", | ||
| }, | ||
| { | ||
| serverURL: "https://server.headscale.com", | ||
| baseDomain: "headscale.com", | ||
| wantErr: errServerURLSuffix.Error(), | ||
| }, | ||
| { | ||
| serverURL: "https://server.subdomain.headscale.com", | ||
| baseDomain: "headscale.com", | ||
| wantErr: errServerURLSuffix.Error(), | ||
| }, | ||
| { | ||
| serverURL: "http://foo\x00", | ||
| wantErr: `parse "http://foo\x00": net/url: invalid control character in URL`, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| testName := fmt.Sprintf("server=%s domain=%s", tt.serverURL, tt.baseDomain) | ||
| t.Run(testName, func(t *testing.T) { | ||
| err := isSafeServerURL(tt.serverURL, tt.baseDomain) | ||
| if tt.wantErr != "" { | ||
| assert.EqualError(t, err, tt.wantErr) | ||
| return | ||
| } | ||
| assert.NoError(t, err) | ||
| }) | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.