Skip to content

Commit 17609cc

Browse files
copilot feedback
1 parent 3302b76 commit 17609cc

3 files changed

Lines changed: 128 additions & 3 deletions

File tree

src/logging.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,10 @@ export class Logger {
243243
* @param optionalParams Additional parameters to log.
244244
*/
245245
public debugOptions(options: any, ...optionalParams: any[]): void {
246+
// Avoid expensive scrubbing and stringification when debug logging is disabled.
247+
if (this.logLevel !== LogLevel.DEBUG) {
248+
return;
249+
}
246250
const scrubbed = this.scrubSensitiveData(options);
247251
this.debug(JSON.stringify(scrubbed), ...optionalParams);
248252
}

src/unity-editor.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,15 +197,18 @@ export class UnityEditor {
197197
* @param args The command-line arguments array.
198198
* @returns A new array with sensitive values redacted.
199199
*/
200-
private scrubSensitiveArgs(args: string[]): string[] {
200+
public scrubSensitiveArgs(args: string[]): string[] {
201201
const sensitiveFlags = ['-username', '-password', '-cloudOrganization', '-serial'];
202202
const scrubbedArgs: string[] = [];
203203

204204
for (let i = 0; i < args.length; i++) {
205-
scrubbedArgs.push(args[i]);
205+
const arg = args[i];
206+
if (!arg) continue;
207+
208+
scrubbedArgs.push(arg);
206209

207210
// If this is a sensitive flag and the next item is its value
208-
if (sensitiveFlags.includes(args[i]) && i + 1 < args.length) {
211+
if (sensitiveFlags.includes(arg) && i + 1 < args.length) {
209212
scrubbedArgs.push('[REDACTED]');
210213
i++; // Skip the next item (the actual value) since we've already added [REDACTED]
211214
}

tests/unity-editor.test.ts

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,122 @@ describe('UnityEditor', () => {
3737
expect(template).toBeDefined();
3838
}
3939
});
40+
41+
describe('scrubSensitiveArgs', () => {
42+
// Create a simple UnityEditor instance for testing scrubSensitiveArgs
43+
// We don't need a full editor setup since we're only testing a pure function
44+
let testEditor: UnityEditor;
45+
46+
beforeAll(() => {
47+
// Use the first available editor or create a mock-like one
48+
if (editors.length > 0) {
49+
testEditor = editors[0];
50+
}
51+
});
52+
53+
it('should redact -username value', () => {
54+
if (!testEditor) {
55+
// Skip if no editors available
56+
return;
57+
}
58+
59+
const args = ['-batchmode', '-username', 'test@example.com', '-quit'];
60+
const scrubbedArgs = testEditor.scrubSensitiveArgs(args);
61+
62+
expect(scrubbedArgs).toContain('-username');
63+
expect(scrubbedArgs).toContain('[REDACTED]');
64+
expect(scrubbedArgs).not.toContain('test@example.com');
65+
expect(scrubbedArgs).toContain('-batchmode');
66+
expect(scrubbedArgs).toContain('-quit');
67+
});
68+
69+
it('should redact -password value', () => {
70+
if (!testEditor) return;
71+
72+
const args = ['-batchmode', '-password', 'SuperSecret123', '-quit'];
73+
const scrubbedArgs = testEditor.scrubSensitiveArgs(args);
74+
75+
expect(scrubbedArgs).toContain('-password');
76+
expect(scrubbedArgs).toContain('[REDACTED]');
77+
expect(scrubbedArgs).not.toContain('SuperSecret123');
78+
});
79+
80+
it('should redact -cloudOrganization value', () => {
81+
if (!testEditor) return;
82+
83+
const args = ['-batchmode', '-cloudOrganization', 'org-id-12345', '-quit'];
84+
const scrubbedArgs = testEditor.scrubSensitiveArgs(args);
85+
86+
expect(scrubbedArgs).toContain('-cloudOrganization');
87+
expect(scrubbedArgs).toContain('[REDACTED]');
88+
expect(scrubbedArgs).not.toContain('org-id-12345');
89+
});
90+
91+
it('should redact -serial value', () => {
92+
if (!testEditor) return;
93+
94+
const args = ['-batchmode', '-serial', 'ABC-123-DEF-456', '-quit'];
95+
const scrubbedArgs = testEditor.scrubSensitiveArgs(args);
96+
97+
expect(scrubbedArgs).toContain('-serial');
98+
expect(scrubbedArgs).toContain('[REDACTED]');
99+
expect(scrubbedArgs).not.toContain('ABC-123-DEF-456');
100+
});
101+
102+
it('should redact multiple sensitive values', () => {
103+
if (!testEditor) return;
104+
105+
const args = [
106+
'-batchmode',
107+
'-username', 'user@example.com',
108+
'-password', 'MyPassword123',
109+
'-cloudOrganization', 'org-xyz',
110+
'-quit'
111+
];
112+
const scrubbedArgs = testEditor.scrubSensitiveArgs(args);
113+
114+
expect(scrubbedArgs).toContain('[REDACTED]');
115+
expect(scrubbedArgs).not.toContain('user@example.com');
116+
expect(scrubbedArgs).not.toContain('MyPassword123');
117+
expect(scrubbedArgs).not.toContain('org-xyz');
118+
expect(scrubbedArgs).toContain('-batchmode');
119+
expect(scrubbedArgs).toContain('-quit');
120+
});
121+
122+
it('should preserve non-sensitive arguments', () => {
123+
if (!testEditor) return;
124+
125+
const args = [
126+
'-batchmode',
127+
'-projectPath', '/path/to/project',
128+
'-buildTarget', 'StandaloneWindows64',
129+
'-quit'
130+
];
131+
const scrubbedArgs = testEditor.scrubSensitiveArgs(args);
132+
133+
expect(scrubbedArgs).toEqual(args);
134+
expect(scrubbedArgs).toContain('/path/to/project');
135+
expect(scrubbedArgs).toContain('StandaloneWindows64');
136+
});
137+
138+
it('should handle empty array', () => {
139+
if (!testEditor) return;
140+
141+
const args: string[] = [];
142+
const scrubbedArgs = testEditor.scrubSensitiveArgs(args);
143+
144+
expect(scrubbedArgs).toEqual([]);
145+
});
146+
147+
it('should handle sensitive flag at end of array without value', () => {
148+
if (!testEditor) return;
149+
150+
const args = ['-batchmode', '-quit', '-username'];
151+
const scrubbedArgs = testEditor.scrubSensitiveArgs(args);
152+
153+
// The flag is included but there's no value to redact
154+
expect(scrubbedArgs).toContain('-username');
155+
expect(scrubbedArgs).not.toContain('[REDACTED]');
156+
});
157+
});
40158
});

0 commit comments

Comments
 (0)