Skip to content

Commit f02b28b

Browse files
mabulguclaude
andcommitted
Add tests for credential redaction and OCI ImagePullSecret provisioning
- Add image_pull_secret to sanitisedValue test coverage - Add OCI provisioning tests with and without ImagePullSecret Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: mabulgu <mabulgu@gmail.com>
1 parent 235a43d commit f02b28b

2 files changed

Lines changed: 99 additions & 6 deletions

File tree

pkg/provisioner/ironic/clients/updateopts_test.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -463,14 +463,16 @@ func TestSanitisedValue(t *testing.T) {
463463
}
464464

465465
unsafe := map[string]any{
466-
"foo": "bar",
467-
"password": "secret",
468-
"ipmi_password": "secret",
466+
"foo": "bar",
467+
"password": "secret",
468+
"ipmi_password": "secret",
469+
"image_pull_secret": "dXNlcjpwYXNz",
469470
}
470471
safe := map[string]any{
471-
"foo": "bar",
472-
"password": "<redacted>",
473-
"ipmi_password": "<redacted>",
472+
"foo": "bar",
473+
"password": "<redacted>",
474+
"ipmi_password": "<redacted>",
475+
"image_pull_secret": "<redacted>",
474476
}
475477
assert.Exactly(t, safe, sanitisedValue(unsafe))
476478
}

pkg/provisioner/ironic/provision_test.go

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1607,6 +1607,97 @@ func TestGetUpdateOptsForNodeSecureBoot(t *testing.T) {
16071607
}
16081608
}
16091609

1610+
func TestGetUpdateOptsForNodeOCIWithPullSecret(t *testing.T) {
1611+
eventPublisher := func(reason, message string) {}
1612+
auth := clients.AuthConfig{Type: clients.NoAuth}
1613+
1614+
host := makeHost()
1615+
host.Spec.Image.URL = "oci://quay.io/test/image:latest"
1616+
host.Spec.Image.Checksum = ""
1617+
host.Spec.Image.ChecksumType = ""
1618+
1619+
prov, err := newProvisionerWithSettings(host, bmc.Credentials{}, eventPublisher, "https://ironic.test", auth)
1620+
if err != nil {
1621+
t.Fatal(err)
1622+
}
1623+
ironicNode := &nodes.Node{}
1624+
1625+
provData := provisioner.ProvisionData{
1626+
Image: *host.Spec.Image,
1627+
BootMode: metal3api.DefaultBootMode,
1628+
ImagePullSecret: "dXNlcjpwYXNz",
1629+
}
1630+
patches := prov.getInstanceUpdateOpts(ironicNode, provData).Updates
1631+
1632+
t.Logf("patches: %v", patches)
1633+
1634+
expected := []struct {
1635+
Path string
1636+
Value any
1637+
}{
1638+
{
1639+
Path: "/instance_info/image_source",
1640+
Value: "oci://quay.io/test/image:latest",
1641+
},
1642+
{
1643+
Path: "/instance_info/image_pull_secret",
1644+
Value: "dXNlcjpwYXNz",
1645+
},
1646+
}
1647+
1648+
for _, e := range expected {
1649+
t.Run(e.Path, func(t *testing.T) {
1650+
var update nodes.UpdateOperation
1651+
for _, patch := range patches {
1652+
u, ok := patch.(nodes.UpdateOperation)
1653+
require.True(t, ok, "expected patch to be UpdateOperation")
1654+
if u.Path == e.Path {
1655+
update = u
1656+
break
1657+
}
1658+
}
1659+
if update.Path != e.Path {
1660+
t.Errorf("did not find %q in updates", e.Path)
1661+
return
1662+
}
1663+
assert.Equal(t, e.Value, update.Value, "%s does not match", e.Path)
1664+
})
1665+
}
1666+
}
1667+
1668+
func TestGetUpdateOptsForNodeOCIWithoutPullSecret(t *testing.T) {
1669+
eventPublisher := func(reason, message string) {}
1670+
auth := clients.AuthConfig{Type: clients.NoAuth}
1671+
1672+
host := makeHost()
1673+
host.Spec.Image.URL = "oci://quay.io/test/image:latest"
1674+
host.Spec.Image.Checksum = ""
1675+
host.Spec.Image.ChecksumType = ""
1676+
1677+
prov, err := newProvisionerWithSettings(host, bmc.Credentials{}, eventPublisher, "https://ironic.test", auth)
1678+
if err != nil {
1679+
t.Fatal(err)
1680+
}
1681+
ironicNode := &nodes.Node{}
1682+
1683+
provData := provisioner.ProvisionData{
1684+
Image: *host.Spec.Image,
1685+
BootMode: metal3api.DefaultBootMode,
1686+
}
1687+
patches := prov.getInstanceUpdateOpts(ironicNode, provData).Updates
1688+
1689+
t.Logf("patches: %v", patches)
1690+
1691+
for _, patch := range patches {
1692+
update, ok := patch.(nodes.UpdateOperation)
1693+
require.True(t, ok, "expected patch to be UpdateOperation")
1694+
if update.Path == "/instance_info/image_pull_secret" {
1695+
assert.Nil(t, update.Value, "image_pull_secret should be nil when no secret is provided")
1696+
return
1697+
}
1698+
}
1699+
}
1700+
16101701
func TestBuildCleanStepsForUpdateFirmware(t *testing.T) {
16111702
nodeUUID := "eec38659-4c68-7431-9535-d10766f07a58"
16121703
cases := []struct {

0 commit comments

Comments
 (0)