-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add --public-addr --cert-file --key-file for teleport configure (#9049)
- Loading branch information
Showing
3 changed files
with
143 additions
and
28 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -107,35 +107,104 @@ func TestMain(m *testing.M) { | |
os.Exit(res) | ||
} | ||
|
||
func TestConfig(t *testing.T) { | ||
t.Run("SampleConfig", func(t *testing.T) { | ||
// generate sample config and write it into a temp file: | ||
sfc, err := MakeSampleFileConfig(SampleFlags{ | ||
ClusterName: "cookie.localhost", | ||
ACMEEnabled: true, | ||
ACMEEmail: "[email protected]", | ||
LicensePath: "/tmp/license.pem", | ||
}) | ||
require.NoError(t, err) | ||
require.NotNil(t, sfc) | ||
fn := filepath.Join(t.TempDir(), "default-config.yaml") | ||
err = os.WriteFile(fn, []byte(sfc.DebugDumpToYAML()), 0660) | ||
require.NoError(t, err) | ||
func TestSampleConfig(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
input SampleFlags | ||
expectError bool | ||
expectClusterName ClusterName | ||
expectLicenseFile string | ||
expectProxyPublicAddrs apiutils.Strings | ||
expectProxyWebAddr string | ||
expectProxyKeyPairs []KeyPair | ||
}{ | ||
{ | ||
name: "ACMEEnabled", | ||
input: SampleFlags{ | ||
ClusterName: "cookie.localhost", | ||
ACMEEnabled: true, | ||
ACMEEmail: "[email protected]", | ||
LicensePath: "/tmp/license.pem", | ||
}, | ||
expectClusterName: ClusterName("cookie.localhost"), | ||
expectLicenseFile: "/tmp/license.pem", | ||
expectProxyPublicAddrs: apiutils.Strings{"cookie.localhost:443"}, | ||
expectProxyWebAddr: "0.0.0.0:443", | ||
}, | ||
{ | ||
name: "public addrs", | ||
input: SampleFlags{ | ||
PublicAddrs: []string{"tele.example.com:443"}, | ||
}, | ||
expectProxyPublicAddrs: apiutils.Strings{"tele.example.com:443"}, | ||
}, | ||
{ | ||
name: "key file missing", | ||
input: SampleFlags{ | ||
CertFile: "/var/lib/teleport/fullchain.pem", | ||
}, | ||
expectError: true, | ||
}, | ||
{ | ||
name: "load x509 key pair failed", | ||
input: SampleFlags{ | ||
KeyFile: "/var/lib/teleport/key.pem", | ||
CertFile: "/var/lib/teleport/fullchain.pem", | ||
}, | ||
expectError: true, | ||
}, | ||
{ | ||
name: "cluster name missing", | ||
input: SampleFlags{ | ||
ACMEEnabled: true, | ||
}, | ||
expectError: true, | ||
}, | ||
{ | ||
name: "ACMEEnabled conflict with key file", | ||
input: SampleFlags{ | ||
ClusterName: "cookie.localhost", | ||
ACMEEnabled: true, | ||
KeyFile: "/var/lib/teleport/privkey.pem", | ||
CertFile: "/var/lib/teleport/fullchain.pem", | ||
}, | ||
expectError: true, | ||
}, | ||
} | ||
|
||
// make sure it could be parsed: | ||
fc, err := ReadFromFile(fn) | ||
require.NoError(t, err) | ||
for _, testCase := range testCases { | ||
t.Run(testCase.name, func(t *testing.T) { | ||
sfc, err := MakeSampleFileConfig(testCase.input) | ||
|
||
if testCase.expectError { | ||
require.Error(t, err) | ||
require.Nil(t, sfc) | ||
return | ||
} | ||
|
||
// validate a couple of values: | ||
require.Equal(t, defaults.DataDir, fc.Global.DataDir) | ||
require.Equal(t, "INFO", fc.Logger.Severity) | ||
require.Equal(t, fc.Auth.ClusterName, ClusterName("cookie.localhost")) | ||
require.Equal(t, fc.Auth.LicenseFile, "/tmp/license.pem") | ||
require.Equal(t, fc.Proxy.PublicAddr, apiutils.Strings{"cookie.localhost:443"}) | ||
require.Equal(t, fc.Proxy.WebAddr, "0.0.0.0:443") | ||
require.NoError(t, err) | ||
require.NotNil(t, sfc) | ||
|
||
require.False(t, lib.IsInsecureDevMode()) | ||
}) | ||
fn := filepath.Join(t.TempDir(), "default-config.yaml") | ||
err = os.WriteFile(fn, []byte(sfc.DebugDumpToYAML()), 0660) | ||
require.NoError(t, err) | ||
|
||
// make sure it could be parsed: | ||
fc, err := ReadFromFile(fn) | ||
require.NoError(t, err) | ||
|
||
// validate a couple of values: | ||
require.Equal(t, fc.Global.DataDir, defaults.DataDir) | ||
require.Equal(t, fc.Logger.Severity, "INFO") | ||
require.Equal(t, testCase.expectClusterName, fc.Auth.ClusterName) | ||
require.Equal(t, testCase.expectLicenseFile, fc.Auth.LicenseFile) | ||
require.Equal(t, testCase.expectProxyWebAddr, fc.Proxy.WebAddr) | ||
require.ElementsMatch(t, testCase.expectProxyPublicAddrs, fc.Proxy.PublicAddr) | ||
require.ElementsMatch(t, testCase.expectProxyKeyPairs, fc.Proxy.KeyPairs) | ||
|
||
require.False(t, lib.IsInsecureDevMode()) | ||
}) | ||
} | ||
} | ||
|
||
// TestBooleanParsing tests that boolean options | ||
|
This file contains 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 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