-
Notifications
You must be signed in to change notification settings - Fork 836
Orbit passes EUA token during enrollment #43369
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
base: 41381-eua-ms-installer
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| * Orbit passes EUA token during enrollment request | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| package client | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "encoding/json" | ||
| "io" | ||
| "net/http" | ||
| "net/http/httptest" | ||
| "testing" | ||
|
|
||
| "github.com/fleetdm/fleet/v4/server/fleet" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestEnrollSendsEUAToken(t *testing.T) { | ||
| // nolint:gosec // not a real credential, test-only JWT fragment | ||
| euaTokenValue := "eyJhbGciOiJSUzI1NiJ9.test-eua-token" | ||
| const testNodeKey = "test-node-key-abc" | ||
|
|
||
| t.Run("eua_token included in enroll request when set", func(t *testing.T) { | ||
| var receivedBody fleet.EnrollOrbitRequest | ||
|
|
||
| srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
| body, err := io.ReadAll(r.Body) | ||
| assert.NoError(t, err) | ||
| assert.NoError(t, json.Unmarshal(body, &receivedBody)) | ||
|
|
||
| resp := fleet.EnrollOrbitResponse{OrbitNodeKey: testNodeKey} | ||
| w.Header().Set("Content-Type", "application/json") | ||
| err = json.NewEncoder(w).Encode(resp) | ||
| assert.NoError(t, err) | ||
| })) | ||
| defer srv.Close() | ||
|
Comment on lines
+24
to
+34
Member
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. Nit. This setup is the same in both subtests. Can this be table-driven? |
||
|
|
||
| oc := &OrbitClient{ | ||
| enrollSecret: "secret", | ||
| hostInfo: fleet.OrbitHostInfo{HardwareUUID: "uuid-1", Platform: "windows"}, | ||
| euaToken: euaTokenValue, | ||
| } | ||
| bc, err := NewBaseClient(srv.URL, true, "", "", nil, fleet.CapabilityMap{}, nil) | ||
| require.NoError(t, err) | ||
| oc.BaseClient = bc | ||
|
|
||
| nodeKey, err := oc.enroll() | ||
| require.NoError(t, err) | ||
| require.Equal(t, testNodeKey, nodeKey) | ||
| require.Equal(t, euaTokenValue, receivedBody.EUAToken) | ||
| require.Equal(t, "secret", receivedBody.EnrollSecret) | ||
| require.Equal(t, "uuid-1", receivedBody.HardwareUUID) | ||
| }) | ||
|
|
||
| t.Run("eua_token omitted from enroll request when empty", func(t *testing.T) { | ||
| var rawBody []byte | ||
|
|
||
| srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
| var err error | ||
| rawBody, err = io.ReadAll(r.Body) | ||
| assert.NoError(t, err) | ||
|
|
||
| resp := fleet.EnrollOrbitResponse{OrbitNodeKey: testNodeKey} | ||
| w.Header().Set("Content-Type", "application/json") | ||
| err = json.NewEncoder(w).Encode(resp) | ||
| assert.NoError(t, err) | ||
| })) | ||
| defer srv.Close() | ||
|
|
||
| oc := &OrbitClient{ | ||
| enrollSecret: "secret", | ||
| hostInfo: fleet.OrbitHostInfo{HardwareUUID: "uuid-1", Platform: "windows"}, | ||
| // euaToken not set — should be omitted from JSON (omitempty) | ||
| } | ||
| bc, err := NewBaseClient(srv.URL, true, "", "", nil, fleet.CapabilityMap{}, nil) | ||
| require.NoError(t, err) | ||
| oc.BaseClient = bc | ||
|
|
||
| _, err = oc.enroll() | ||
| require.NoError(t, err) | ||
|
|
||
| // Verify the eua_token key is not present in the JSON body. | ||
| require.Falsef(t, bytes.Contains(rawBody, []byte(`"eua_token"`)), | ||
| "eua_token should not appear in JSON when empty, got: %s", string(rawBody)) | ||
| }) | ||
| } | ||
|
|
||
| func TestSetEUAToken(t *testing.T) { | ||
| oc := &OrbitClient{} | ||
| require.Empty(t, oc.euaToken) | ||
|
|
||
| oc.SetEUAToken("some-token") | ||
| require.Equal(t, "some-token", oc.euaToken) | ||
|
|
||
| oc.SetEUAToken("") | ||
| require.Empty(t, oc.euaToken) | ||
| } | ||
|
Comment on lines
+86
to
+95
Member
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. Nit. This is already covered by the test above. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| package packaging | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestWindowsWixTemplateEUAToken(t *testing.T) { | ||
| baseOpt := Options{ | ||
| FleetURL: "https://fleet.example.com", | ||
| EnrollSecret: "secret", | ||
| OrbitChannel: "stable", | ||
| OsquerydChannel: "stable", | ||
| DesktopChannel: "stable", | ||
| NativePlatform: "windows", | ||
| Architecture: ArchAmd64, | ||
| } | ||
|
|
||
| t.Run("EUA_TOKEN property and flag included when enabled", func(t *testing.T) { | ||
| opt := baseOpt | ||
| opt.EnableEUATokenProperty = true | ||
|
|
||
| var buf bytes.Buffer | ||
| err := windowsWixTemplate.Execute(&buf, opt) | ||
| require.NoError(t, err) | ||
|
|
||
| output := buf.String() | ||
| assert.Contains(t, output, `<Property Id="EUA_TOKEN" Value="dummy"/>`) | ||
| assert.Contains(t, output, `--eua-token="[EUA_TOKEN]"`) | ||
| }) | ||
|
|
||
| t.Run("EUA_TOKEN property and flag absent when disabled", func(t *testing.T) { | ||
| opt := baseOpt | ||
| opt.EnableEUATokenProperty = false | ||
|
|
||
| var buf bytes.Buffer | ||
| err := windowsWixTemplate.Execute(&buf, opt) | ||
| require.NoError(t, err) | ||
|
|
||
| output := buf.String() | ||
| assert.NotContains(t, output, `EUA_TOKEN`) | ||
| assert.NotContains(t, output, `--eua-token`) | ||
| }) | ||
|
|
||
| t.Run("EUA_TOKEN flag appears in ServiceInstall Arguments", func(t *testing.T) { | ||
| opt := baseOpt | ||
| opt.EnableEUATokenProperty = true | ||
|
|
||
| var buf bytes.Buffer | ||
| err := windowsWixTemplate.Execute(&buf, opt) | ||
| require.NoError(t, err) | ||
|
|
||
| // Find the ServiceInstall Arguments line and verify eua-token is in it. | ||
| for line := range strings.SplitSeq(buf.String(), "\n") { | ||
| if strings.Contains(line, "Arguments=") && strings.Contains(line, "--fleet-url") { | ||
| assert.Contains(t, line, `--eua-token="[EUA_TOKEN]"`, | ||
| "eua-token flag should be in ServiceInstall Arguments") | ||
| return | ||
| } | ||
| } | ||
|
Comment on lines
+49
to
+64
Member
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. Nit. This could be merged with test 1. |
||
| t.Fatal("ServiceInstall Arguments line not found in template output") | ||
| }) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be in orbit/changes/ directory