Skip to content

Commit 5d3770e

Browse files
authored
Adding new webhook test secret (#333)
* Adding new webhook test secret * Minor refactoring.
1 parent 1c6409e commit 5d3770e

File tree

2 files changed

+167
-16
lines changed

2 files changed

+167
-16
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
apiVersion: fleet.cattle.io/v1alpha1
2+
kind: GitRepo
3+
metadata:
4+
name: webhook-test-disable-polling
5+
namespace: fleet-local
6+
spec:
7+
branch: main
8+
correctDrift:
9+
enabled: false
10+
insecureSkipTLSVerify: false
11+
repo: https://github.com/fleetqa/webhook-github-test
12+
disablePolling: true
13+
webhookSecret: wrong-secret-name
14+
targets:
15+
- clusterSelector:
16+
matchExpressions:
17+
- key: provider.cattle.io
18+
operator: NotIn
19+
values:
20+
- harvester
21+
__clone: true

tests/cypress/e2e/unit_tests/p0_fleet.spec.ts

Lines changed: 146 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -379,30 +379,50 @@ describe('Test gitrepos with cabundle', { tags: '@p0' }, () => {
379379
});
380380

381381
if (!/\/2\.7/.test(Cypress.env('rancher_version')) && !/\/2\.8/.test(Cypress.env('rancher_version'))) {
382+
382383
describe('Test Fleet with Webhook', { tags: '@p0' }, () => {
384+
385+
const gh_private_pwd = Cypress.env('gh_private_pwd');
386+
387+
before('Preparing Github Webhook', () => {
388+
389+
// Prepare webhook in Github
390+
cy.exec('bash assets/webhook-tests/webhook_setup.sh', { env: { gh_private_pwd } }).then((result) => {
391+
cy.log(result.stdout, result.stderr);
392+
})
393+
394+
cy.login();
395+
396+
// Open local terminal in Rancher UI
397+
cy.accesMenuSelection('local');
398+
cy.get('#btn-kubectl').click();
399+
cy.contains('Connected').should('be.visible');
400+
401+
// Add yaml file to the terminal to create ad-hoc ingress
402+
cy.get('button > i.icon.icon-upload.icon-lg').click();
403+
cy.addYamlFile('assets/webhook-tests/webhook_ingress.yaml');
404+
cy.clickButton('Import');
405+
cy.clickButton('Close');
406+
407+
});
408+
383409
qase(152,
410+
384411
it('Fleet-152: Test Fleet with Webhook and disable polling ', { tags: '@fleet-152' }, () => {
385412

386413
const repoName = 'webhook-test-disable-polling';
387-
const gh_private_pwd = Cypress.env('gh_private_pwd');
388414

389-
// Prepare webhook in Github
390-
cy.exec('bash assets/webhook-tests/webhook_setup.sh', { env: { gh_private_pwd } }).then((result) => {
391-
cy.log(result.stdout, result.stderr);
392-
})
415+
cy.exec('bash assets/webhook-tests/webhook_test_2_replicas.sh').then((result) => {
416+
cy.log(result.stdout, result.stderr);
417+
});
393418

394419
// Open local terminal in Rancher UI
395420
cy.accesMenuSelection('local');
396421
cy.get('#btn-kubectl').click();
397422
cy.contains('Connected').should('be.visible');
398423

399-
// Add yaml file to the terminal to create ad-hoc ingress
400-
cy.get('button > i.icon.icon-upload.icon-lg').click();
401-
cy.addYamlFile('assets/webhook-tests/webhook_ingress.yaml');
402-
cy.clickButton('Import');
403-
cy.clickButton('Close');
404-
405424
cy.typeIntoCanvasTermnal('\
425+
kubectl delete secrets -n cattle-fleet-system gitjob-webhook{enter} \
406426
kubectl create secret generic gitjob-webhook -n cattle-fleet-system --from-literal=github=webhooksecretvalue{enter}');
407427

408428
// Ensure webhook repo starts with 2 replicas
@@ -428,11 +448,6 @@ if (!/\/2\.7/.test(Cypress.env('rancher_version')) && !/\/2\.8/.test(Cypress.env
428448
cy.contains('tr.main-row', repoName, { timeout: 20000 }).should('be.visible');
429449
cy.verifyTableRow(0, 'Active', '2/2');
430450

431-
// Give extra time for job to finsih.
432-
// TODO: remove this wait once https://github.com/rancher/fleet/issues/3067 is fixed
433-
// or find a way to wait for the job to finish
434-
cy.wait(10000);
435-
436451
// Change replicas to 5
437452
cy.exec('bash assets/webhook-tests/webhook_test_5_replicas.sh').then((result) => {
438453
cy.log(result.stdout, result.stderr);
@@ -442,6 +457,120 @@ if (!/\/2\.7/.test(Cypress.env('rancher_version')) && !/\/2\.8/.test(Cypress.env
442457
cy.verifyTableRow(0, 'Active', '5/5');
443458
})
444459
);
460+
461+
if (!/\/2\.9/.test(Cypress.env('rancher_version')) && !/\/2\.10/.test(Cypress.env('rancher_version')) && !/\/2\.11/.test(Cypress.env('rancher_version'))) {
462+
463+
qase(178,
464+
465+
it('Fleet-178: Test Fleet with Webhook and secret on gitrepo directly ', { tags: '@fleet-178' }, () => {
466+
467+
const repoName = 'test-disable-polling';
468+
469+
// Reset test to 2 replicas in case is not reset
470+
cy.exec('bash assets/webhook-tests/webhook_test_2_replicas.sh').then((result) => {
471+
cy.log(result.stdout, result.stderr);
472+
});
473+
474+
// Open local terminal in Rancher UI
475+
cy.accesMenuSelection('local');
476+
cy.get('#btn-kubectl').click();
477+
cy.contains('Connected').should('be.visible');
478+
479+
// CHANGE TO REMOVE EXISTING SECRET
480+
cy.typeIntoCanvasTermnal('\
481+
kubectl delete secrets -n cattle-fleet-system gitjob-webhook{enter}');
482+
483+
// Gitrepo creation via YAML
484+
cy.accesMenuSelection('Continuous Delivery', 'Git Repos');
485+
cy.fleetNamespaceToggle('fleet-local');
486+
cy.clickButton('Add Repository');
487+
cy.clickButton('Edit as YAML');
488+
489+
cy.addYamlFile('assets/webhook-tests/webhook_test_webhook_secret_in_repo.yaml');
490+
cy.clickButton('Create');
491+
cy.verifyTableRow(0, 'Active', '1/1');
492+
cy.checkGitRepoStatus(repoName, '1 / 1', '1 / 1');
493+
494+
cy.verifyJobDeleted(repoName, false);
495+
496+
// Verify deployments have 2 replicas only
497+
cy.accesMenuSelection('local', 'Workloads', 'Deployments');
498+
cy.filterInSearchBox(repoName);
499+
cy.wait(500);
500+
cy.contains('tr.main-row', repoName, { timeout: 20000 }).should('be.visible');
501+
cy.verifyTableRow(0, 'Active', '2/2');
502+
503+
// Change replicas to 5 in Github Webhook
504+
cy.exec('bash assets/webhook-tests/webhook_test_5_replicas.sh').then((result) => {
505+
cy.log(result.stdout, result.stderr);
506+
});
507+
508+
// Verify deployments STILL HAVE 2 replicas and NOT 5
509+
cy.verifyTableRow(0, 'Active', '2/2');
510+
511+
// Verify error on log
512+
cy.accesMenuSelection('local', 'Workloads', 'Pods');
513+
cy.filterInSearchBox('gitjob')
514+
cy.open3dotsMenu('gitjob', 'View Logs')
515+
cy.contains('"Webhook processing failed"').should('exist');
516+
})
517+
)
518+
519+
qase(177,
520+
521+
it('Fleet-177: Test Fleet with Webhook and secret using "gitjob-webhhook" on "cattle-fleet-system" ', { tags: '@fleet-177' }, () => {
522+
523+
const repoName = 'test-disable-polling';
524+
525+
// Reset test to 2 replicas in case is not reset
526+
cy.exec('bash assets/webhook-tests/webhook_test_2_replicas.sh').then((result) => {
527+
cy.log(result.stdout, result.stderr);
528+
});
529+
530+
// Open local terminal in Rancher UI
531+
cy.accesMenuSelection('local');
532+
cy.get('#btn-kubectl').click();
533+
cy.contains('Connected').should('be.visible');
534+
535+
// Adding wrong generic secret
536+
cy.typeIntoCanvasTermnal('\
537+
kubectl create secret generic gitjob-webhook -n cattle-fleet-system --from-literal=github=wrong-webhook-secret{enter}');
538+
539+
// Gitrepo creation via YAML
540+
cy.accesMenuSelection('Continuous Delivery', 'Git Repos');
541+
cy.fleetNamespaceToggle('fleet-local');
542+
cy.clickButton('Add Repository');
543+
cy.clickButton('Edit as YAML');
544+
545+
cy.addYamlFile('assets/webhook-tests/webhook_test_disable_polling.yaml');
546+
cy.clickButton('Create');
547+
cy.verifyTableRow(0, 'Active', '1/1');
548+
cy.checkGitRepoStatus(repoName, '1 / 1', '1 / 1');
549+
550+
cy.verifyJobDeleted(repoName, false);
551+
552+
// Verify deployments has 2 replicas only
553+
cy.accesMenuSelection('local', 'Workloads', 'Deployments');
554+
cy.filterInSearchBox(repoName);
555+
cy.wait(500);
556+
cy.contains('tr.main-row', repoName, { timeout: 20000 }).should('be.visible');
557+
cy.verifyTableRow(0, 'Active', '2/2');
558+
559+
// Change replicas to 5 in Github Webhook
560+
cy.exec('bash assets/webhook-tests/webhook_test_5_replicas.sh').then((result) => {
561+
cy.log(result.stdout, result.stderr);
562+
});
563+
564+
// Verify deployments STILL HAVE 2 replicas and NOT 5
565+
cy.verifyTableRow(0, 'Active', '2/2');
566+
567+
// Verify error on log
568+
cy.accesMenuSelection('local', 'Workloads', 'Pods');
569+
cy.filterInSearchBox('gitjob')
570+
cy.open3dotsMenu('gitjob', 'View Logs')
571+
cy.contains('HMAC verification failed').should('exist');
572+
})
573+
)}
445574
})
446575
};
447576

@@ -552,6 +681,7 @@ if (!/\/2\.7/.test(Cypress.env('rancher_version')) && !/\/2\.8/.test(Cypress.env
552681
cy.get('table > tbody > tr').contains(repoName).should('be.visible');
553682
})
554683
)});
684+
555685
};
556686

557687
if (!/\/2\.8/.test(Cypress.env('rancher_version')) && !/\/2\.9/.test(Cypress.env('rancher_version'))) {

0 commit comments

Comments
 (0)