@@ -140,4 +140,94 @@ describe('Git Operations', () => {
140140 expect ( result ) . toSucceed ( ) ;
141141 } , 180000 ) ;
142142 } ) ;
143+
144+ describe ( 'Authenticated Git Operations' , ( ) => {
145+ const hasToken = ! ! process . env . GITHUB_TOKEN ;
146+ const TEST_REPO = 'Mossaka/gh-aw-firewall-test-node' ;
147+
148+ // Helper to build a bash command that configures git credentials, then runs the given commands
149+ const withGitAuth = ( commands : string ) : string =>
150+ `bash -c 'git config --global user.email "awf-test@github.com" && ` +
151+ `git config --global user.name "AWF Test" && ` +
152+ `git config --global credential.helper "!f() { echo username=x-access-token; echo password=\\$GITHUB_TOKEN; }; f" && ` +
153+ `${ commands } '` ;
154+
155+ const skipReason = 'GITHUB_TOKEN not available' ;
156+
157+ test ( 'should clone with authentication' , async ( ) => {
158+ if ( ! hasToken ) {
159+ console . log ( `Skipping: ${ skipReason } ` ) ;
160+ return ;
161+ }
162+
163+ const result = await runner . runWithSudo (
164+ withGitAuth (
165+ `git clone --depth 1 https://github.com/${ TEST_REPO } .git /tmp/auth-clone && ls /tmp/auth-clone`
166+ ) ,
167+ {
168+ allowDomains : [ 'github.com' ] ,
169+ logLevel : 'debug' ,
170+ timeout : 120000 ,
171+ }
172+ ) ;
173+
174+ expect ( result ) . toSucceed ( ) ;
175+ expect ( result . stdout ) . toMatch ( / p a c k a g e \. j s o n | R E A D M E / ) ;
176+ } , 180000 ) ;
177+
178+ test ( 'should fetch after authenticated clone' , async ( ) => {
179+ if ( ! hasToken ) {
180+ console . log ( `Skipping: ${ skipReason } ` ) ;
181+ return ;
182+ }
183+
184+ const result = await runner . runWithSudo (
185+ withGitAuth (
186+ `git clone --depth 1 https://github.com/${ TEST_REPO } .git /tmp/auth-fetch && ` +
187+ `cd /tmp/auth-fetch && git fetch origin`
188+ ) ,
189+ {
190+ allowDomains : [ 'github.com' ] ,
191+ logLevel : 'debug' ,
192+ timeout : 120000 ,
193+ }
194+ ) ;
195+
196+ expect ( result ) . toSucceed ( ) ;
197+ } , 180000 ) ;
198+
199+ test ( 'should push to remote and clean up temp branch' , async ( ) => {
200+ if ( ! hasToken ) {
201+ console . log ( `Skipping: ${ skipReason } ` ) ;
202+ return ;
203+ }
204+
205+ const branchName = `test/awf-push-${ Date . now ( ) } ` ;
206+
207+ // Clone, create branch, commit, push, then delete the remote branch
208+ const result = await runner . runWithSudo (
209+ withGitAuth (
210+ `git clone --depth 1 https://github.com/${ TEST_REPO } .git /tmp/auth-push && ` +
211+ `cd /tmp/auth-push && ` +
212+ `git checkout -b ${ branchName } && ` +
213+ `echo "awf-test-$(date +%s)" > awf-test-file.txt && ` +
214+ `git add awf-test-file.txt && ` +
215+ `git commit -m "test: awf push test" && ` +
216+ `git push origin ${ branchName } && ` +
217+ `echo "PUSH_SUCCESS" && ` +
218+ `git push origin --delete ${ branchName } && ` +
219+ `echo "CLEANUP_SUCCESS"`
220+ ) ,
221+ {
222+ allowDomains : [ 'github.com' ] ,
223+ logLevel : 'debug' ,
224+ timeout : 180000 ,
225+ }
226+ ) ;
227+
228+ expect ( result ) . toSucceed ( ) ;
229+ expect ( result . stdout ) . toContain ( 'PUSH_SUCCESS' ) ;
230+ expect ( result . stdout ) . toContain ( 'CLEANUP_SUCCESS' ) ;
231+ } , 240000 ) ;
232+ } ) ;
143233} ) ;
0 commit comments