|
| 1 | +// SPDX-FileCopyrightText: 2025 SAP SE or an SAP affiliate company and IronCore contributors |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +package server |
| 5 | + |
| 6 | +import ( |
| 7 | + "encoding/json" |
| 8 | + "net/http" |
| 9 | + |
| 10 | + . "github.com/onsi/ginkgo/v2" |
| 11 | + . "github.com/onsi/gomega" |
| 12 | +) |
| 13 | + |
| 14 | +type httpBootResponse struct { |
| 15 | + ClientIPs string `json:"ClientIPs"` |
| 16 | + UKIURL string `json:"UKIURL"` |
| 17 | + SystemUUID string `json:"SystemUUID,omitempty"` |
| 18 | +} |
| 19 | + |
| 20 | +var _ = Describe("BootServer", func() { |
| 21 | + Context("/httpboot endpoint", func() { |
| 22 | + It("delivers default httpboot data when no HTTPBootConfig matches the client IP", func() { |
| 23 | + resp, err := http.Get(testServerURL + "/httpboot") |
| 24 | + Expect(err).NotTo(HaveOccurred()) |
| 25 | + defer func() { |
| 26 | + _ = resp.Body.Close() |
| 27 | + }() |
| 28 | + |
| 29 | + Expect(resp.StatusCode).To(Equal(http.StatusOK)) |
| 30 | + Expect(resp.Header.Get("Content-Type")).To(Equal("application/json")) |
| 31 | + |
| 32 | + var body httpBootResponse |
| 33 | + Expect(json.NewDecoder(resp.Body).Decode(&body)).To(Succeed()) |
| 34 | + |
| 35 | + By("returning the default UKI URL") |
| 36 | + Expect(body.UKIURL).To(Equal(defaultUKIURL)) |
| 37 | + |
| 38 | + By("including the recorded client IPs") |
| 39 | + Expect(body.ClientIPs).NotTo(BeEmpty()) |
| 40 | + |
| 41 | + By("not setting a SystemUUID in the default case") |
| 42 | + Expect(body.SystemUUID).To(SatisfyAny(BeEmpty(), Equal(""))) |
| 43 | + }) |
| 44 | + }) |
| 45 | + |
| 46 | + It("converts valid Butane YAML to JSON", func() { |
| 47 | + butaneYAML := []byte(` |
| 48 | +variant: fcos |
| 49 | +version: 1.5.0 |
| 50 | +systemd: |
| 51 | + units: |
| 52 | + - name: test.service |
| 53 | + enabled: true |
| 54 | +`) |
| 55 | + |
| 56 | + jsonData, err := renderIgnition(butaneYAML) |
| 57 | + Expect(err).ToNot(HaveOccurred()) |
| 58 | + Expect(jsonData).ToNot(BeEmpty()) |
| 59 | + Expect(string(jsonData)).To(ContainSubstring(`"systemd"`)) |
| 60 | + }) |
| 61 | + |
| 62 | + It("returns an error for invalid YAML", func() { |
| 63 | + bad := []byte("this ::: is not yaml") |
| 64 | + _, err := renderIgnition(bad) |
| 65 | + Expect(err).To(HaveOccurred()) |
| 66 | + }) |
| 67 | +}) |
0 commit comments