Skip to content

Commit 1349346

Browse files
committed
Also delete fsGroup and runAsUser when undefined
The parent security context object may not include these fields at all, leaving them as undefined after the spread in data(). The existing empty-string and null guards did not cover this case.
1 parent ccc0faf commit 1349346

2 files changed

Lines changed: 39 additions & 2 deletions

File tree

shell/components/form/Security.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,11 @@ export default {
141141
}
142142
143143
// Drop empty values so we don't send a string for int64 fields.
144-
if (securityContext.fsGroup === '' || securityContext.fsGroup === null) {
144+
if (securityContext.fsGroup === '' || securityContext.fsGroup === null || securityContext.fsGroup === undefined) {
145145
delete securityContext.fsGroup;
146146
}
147147
148-
if (securityContext.runAsUser === '' || securityContext.runAsUser === null) {
148+
if (securityContext.runAsUser === '' || securityContext.runAsUser === null || securityContext.runAsUser === undefined) {
149149
delete securityContext.runAsUser;
150150
}
151151

shell/components/form/__tests__/Security.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,23 @@ describe('component: Security', () => {
9898
expect(Object.prototype.hasOwnProperty.call(last, 'runAsUser')).toBe(false);
9999
});
100100

101+
it('should omit runAsUser from the emitted value when it is undefined', async() => {
102+
const wrapper = mount(Security, {
103+
props: {
104+
mode: _EDIT, formType: FORM_TYPES.CONTAINER, value: {}
105+
}
106+
});
107+
108+
const checkbox = wrapper.find('[data-testid="input-security-runasNonRoot"]').find('label');
109+
110+
await checkbox.trigger('click');
111+
112+
const events = wrapper.emitted('update:value') ?? [];
113+
const last = events[events.length - 1][0] as Record<string, unknown>;
114+
115+
expect(Object.prototype.hasOwnProperty.call(last, 'runAsUser')).toBe(false);
116+
});
117+
101118
it.each([
102119
'privileged',
103120
'allowPrivilegeEscalation',
@@ -159,6 +176,26 @@ describe('component: Security', () => {
159176
expect(wrapper.emitted('update:value')).toHaveLength(1);
160177
});
161178

179+
it.each([
180+
'runAsUser',
181+
'fsGroup',
182+
])('should omit %p from the emitted value when it is undefined', async(field) => {
183+
const wrapper = mount(Security, {
184+
props: {
185+
mode: _EDIT, formType: FORM_TYPES.POD, value: {}
186+
}
187+
});
188+
189+
const checkbox = wrapper.find('[data-testid="input-security-runasNonRoot"]').find('label');
190+
191+
await checkbox.trigger('click');
192+
193+
const events = wrapper.emitted('update:value') ?? [];
194+
const last = events[events.length - 1][0] as Record<string, unknown>;
195+
196+
expect(Object.prototype.hasOwnProperty.call(last, field)).toBe(false);
197+
});
198+
162199
// Regression for #9601 — see equivalent container-level test above.
163200
it.each([
164201
['runAsUser', { runAsUser: 33 }],

0 commit comments

Comments
 (0)