@@ -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