Skip to content

Commit c2bb003

Browse files
Mossakaclaude
andcommitted
test: add authenticated git operations integration tests
Add tests for git clone, fetch, and push with GITHUB_TOKEN authentication through the AWF proxy. Tests skip gracefully when GITHUB_TOKEN is not available. Push test creates a temporary branch and cleans up after itself. Closes #1045 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 1a28945 commit c2bb003

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed

tests/integration/git-operations.test.ts

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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(/package\.json|README/);
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

Comments
 (0)