Skip to content

Commit ab8941f

Browse files
authored
trustpub: Remove workflow path verification from the frontend (#12431)
Unfortunately this wasn't working as intended on production due to CORS issues. We could proxy the requests through our API servers, but for this nice to have feature I'm not sure it's worth the extra complexity for now.
1 parent 59de034 commit ab8941f

File tree

5 files changed

+3
-184
lines changed

5 files changed

+3
-184
lines changed

app/controllers/crate/settings/new-trusted-publisher.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,10 @@ export default class NewTrustedPublisherController extends Controller {
3434
}
3535

3636
get verificationUrl() {
37+
if (this.publisher !== 'GitHub') return;
3738
if (!this.namespace || !this.project || !this.workflow) return;
3839

39-
if (this.publisher === 'GitHub') {
40-
return `https://raw.githubusercontent.com/${this.namespace}/${this.project}/HEAD/.github/workflows/${this.workflow}`;
41-
}
42-
43-
if (this.publisher === 'GitLab') {
44-
return `https://gitlab.com/${this.namespace}/${this.project}/-/raw/HEAD/${this.workflow}`;
45-
}
40+
return `https://raw.githubusercontent.com/${this.namespace}/${this.project}/HEAD/.github/workflows/${this.workflow}`;
4641
}
4742

4843
saveConfigTask = task(async () => {

app/templates/crate/settings/new-trusted-publisher.gjs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,6 @@ import WorkflowVerification from 'crates-io/components/workflow-verification';
274274
<code>ci/publish.yml</code>.
275275
</div>
276276
{{/if}}
277-
278-
<WorkflowVerification @url={{@controller.verificationUrl}} @fieldType='filepath' />
279277
{{/let}}
280278
</div>
281279

e2e/routes/crate/settings/new-trusted-publisher.spec.ts

Lines changed: 0 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -505,93 +505,5 @@ test.describe('Route | crate.settings.new-trusted-publisher', { tag: '@routes' }
505505
await expect(page).toHaveURL(`/crates/${crate.name}/settings`);
506506
await expect(page.locator('[data-test-gitlab-config]')).toHaveCount(0);
507507
});
508-
509-
test.describe('workflow verification', () => {
510-
test('success case (200 OK)', async ({ msw, page }) => {
511-
let { crate } = await prepare(msw);
512-
513-
await page.goto(`/crates/${crate.name}/settings/new-trusted-publisher`);
514-
await expect(page).toHaveURL(`/crates/${crate.name}/settings/new-trusted-publisher`);
515-
516-
// Select GitLab from the publisher dropdown
517-
await page.selectOption('[data-test-publisher]', 'GitLab');
518-
519-
await msw.worker.use(
520-
http.head('https://gitlab.com/rust-lang/crates.io/-/raw/HEAD/.gitlab-ci.yml', () => {
521-
return new HttpResponse(null, { status: 200 });
522-
}),
523-
);
524-
525-
await expect(page.locator('[data-test-workflow-verification="initial"]')).toHaveText(
526-
'The workflow filepath will be verified once all necessary fields are filled.',
527-
);
528-
529-
await page.fill('[data-test-namespace]', 'rust-lang');
530-
await page.fill('[data-test-project]', 'crates.io');
531-
await page.fill('[data-test-workflow]', '.gitlab-ci.yml');
532-
533-
await expect(page.locator('[data-test-workflow-verification="success"]')).toBeVisible();
534-
535-
await expect(page.locator('[data-test-workflow-verification="success"]')).toHaveText(
536-
'✓ Workflow file found at https://gitlab.com/rust-lang/crates.io/-/raw/HEAD/.gitlab-ci.yml',
537-
);
538-
});
539-
540-
test('not found case (404)', async ({ msw, page }) => {
541-
let { crate } = await prepare(msw);
542-
543-
await page.goto(`/crates/${crate.name}/settings/new-trusted-publisher`);
544-
await expect(page).toHaveURL(`/crates/${crate.name}/settings/new-trusted-publisher`);
545-
546-
// Select GitLab from the publisher dropdown
547-
await page.selectOption('[data-test-publisher]', 'GitLab');
548-
549-
await msw.worker.use(
550-
http.head('https://gitlab.com/rust-lang/crates.io/-/raw/HEAD/missing.yml', () => {
551-
return new HttpResponse(null, { status: 404 });
552-
}),
553-
);
554-
555-
await page.fill('[data-test-namespace]', 'rust-lang');
556-
await page.fill('[data-test-project]', 'crates.io');
557-
await page.fill('[data-test-workflow]', 'missing.yml');
558-
559-
await expect(page.locator('[data-test-workflow-verification="not-found"]')).toBeVisible();
560-
561-
await expect(page.locator('[data-test-workflow-verification="not-found"]')).toHaveText(
562-
'⚠ Workflow file not found at https://gitlab.com/rust-lang/crates.io/-/raw/HEAD/missing.yml',
563-
);
564-
565-
// Verify form can still be submitted
566-
await page.click('[data-test-add]');
567-
await expect(page).toHaveURL(`/crates/${crate.name}/settings`);
568-
});
569-
570-
test('server error (5xx)', async ({ msw, page }) => {
571-
let { crate } = await prepare(msw);
572-
573-
await page.goto(`/crates/${crate.name}/settings/new-trusted-publisher`);
574-
await expect(page).toHaveURL(`/crates/${crate.name}/settings/new-trusted-publisher`);
575-
576-
// Select GitLab from the publisher dropdown
577-
await page.selectOption('[data-test-publisher]', 'GitLab');
578-
579-
await msw.worker.use(
580-
http.head('https://gitlab.com/rust-lang/crates.io/-/raw/HEAD/.gitlab-ci.yml', () => {
581-
return new HttpResponse(null, { status: 500 });
582-
}),
583-
);
584-
585-
await page.fill('[data-test-namespace]', 'rust-lang');
586-
await page.fill('[data-test-project]', 'crates.io');
587-
await page.fill('[data-test-workflow]', '.gitlab-ci.yml');
588-
589-
await expect(page.locator('[data-test-workflow-verification="error"]')).toBeVisible();
590-
591-
await expect(page.locator('[data-test-workflow-verification="error"]')).toHaveText(
592-
'⚠ Could not verify workflow file at https://gitlab.com/rust-lang/crates.io/-/raw/HEAD/.gitlab-ci.yml (network error)',
593-
);
594-
});
595-
});
596508
});
597509
});

src/config/server.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ impl Server {
179179
// the `script` in `public/github-redirect.html`
180180
let content_security_policy = format!(
181181
"default-src 'self'; \
182-
connect-src 'self' *.ingest.sentry.io https://docs.rs https://play.rust-lang.org https://raw.githubusercontent.com https://gitlab.com {cdn_domain}; \
182+
connect-src 'self' *.ingest.sentry.io https://docs.rs https://play.rust-lang.org https://raw.githubusercontent.com {cdn_domain}; \
183183
script-src 'self' 'unsafe-eval' 'sha256-n1+BB7Ckjcal1Pr7QNBh/dKRTtBQsIytFodRiIosXdE=' 'sha256-dbf9FMl76C7BnK1CC3eWb3pvsQAUaTYSHAlBy9tNTG0='; \
184184
style-src 'self' 'unsafe-inline' https://code.cdn.mozilla.net; \
185185
font-src https://code.cdn.mozilla.net; \

tests/routes/crate/settings/new-trusted-publisher-test.js

Lines changed: 0 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -514,91 +514,5 @@ module('Route | crate.settings.new-trusted-publisher', hooks => {
514514
assert.strictEqual(currentURL(), `/crates/${crate.name}/settings`);
515515
assert.dom('[data-test-gitlab-config]').exists({ count: 0 });
516516
});
517-
518-
module('workflow verification', function () {
519-
test('success case (200 OK)', async function (assert) {
520-
let { crate } = await prepare(this);
521-
522-
await visit(`/crates/${crate.name}/settings/new-trusted-publisher`);
523-
assert.strictEqual(currentURL(), `/crates/${crate.name}/settings/new-trusted-publisher`);
524-
525-
// Select GitLab from the publisher dropdown
526-
await fillIn('[data-test-publisher]', 'GitLab');
527-
528-
this.worker.use(
529-
http.head('https://gitlab.com/rust-lang/crates.io/-/raw/HEAD/.gitlab-ci.yml', () => {
530-
return new HttpResponse(null, { status: 200 });
531-
}),
532-
);
533-
534-
assert
535-
.dom('[data-test-workflow-verification="initial"]')
536-
.hasText('The workflow filepath will be verified once all necessary fields are filled.');
537-
538-
await fillIn('[data-test-namespace]', 'rust-lang');
539-
await fillIn('[data-test-project]', 'crates.io');
540-
await fillIn('[data-test-workflow]', '.gitlab-ci.yml');
541-
542-
await waitFor('[data-test-workflow-verification="success"]');
543-
544-
let expected = '✓ Workflow file found at https://gitlab.com/rust-lang/crates.io/-/raw/HEAD/.gitlab-ci.yml';
545-
assert.dom('[data-test-workflow-verification="success"]').hasText(expected);
546-
});
547-
548-
test('not found case (404)', async function (assert) {
549-
let { crate } = await prepare(this);
550-
551-
await visit(`/crates/${crate.name}/settings/new-trusted-publisher`);
552-
assert.strictEqual(currentURL(), `/crates/${crate.name}/settings/new-trusted-publisher`);
553-
554-
// Select GitLab from the publisher dropdown
555-
await fillIn('[data-test-publisher]', 'GitLab');
556-
557-
this.worker.use(
558-
http.head('https://gitlab.com/rust-lang/crates.io/-/raw/HEAD/missing.yml', () => {
559-
return new HttpResponse(null, { status: 404 });
560-
}),
561-
);
562-
563-
await fillIn('[data-test-namespace]', 'rust-lang');
564-
await fillIn('[data-test-project]', 'crates.io');
565-
await fillIn('[data-test-workflow]', 'missing.yml');
566-
567-
await waitFor('[data-test-workflow-verification="not-found"]');
568-
569-
let expected = '⚠ Workflow file not found at https://gitlab.com/rust-lang/crates.io/-/raw/HEAD/missing.yml';
570-
assert.dom('[data-test-workflow-verification="not-found"]').hasText(expected);
571-
572-
// Verify form can still be submitted
573-
await click('[data-test-add]');
574-
assert.strictEqual(currentURL(), `/crates/${crate.name}/settings`);
575-
});
576-
577-
test('server error (5xx)', async function (assert) {
578-
let { crate } = await prepare(this);
579-
580-
await visit(`/crates/${crate.name}/settings/new-trusted-publisher`);
581-
assert.strictEqual(currentURL(), `/crates/${crate.name}/settings/new-trusted-publisher`);
582-
583-
// Select GitLab from the publisher dropdown
584-
await fillIn('[data-test-publisher]', 'GitLab');
585-
586-
this.worker.use(
587-
http.head('https://gitlab.com/rust-lang/crates.io/-/raw/HEAD/.gitlab-ci.yml', () => {
588-
return new HttpResponse(null, { status: 500 });
589-
}),
590-
);
591-
592-
await fillIn('[data-test-namespace]', 'rust-lang');
593-
await fillIn('[data-test-project]', 'crates.io');
594-
await fillIn('[data-test-workflow]', '.gitlab-ci.yml');
595-
596-
await waitFor('[data-test-workflow-verification="error"]');
597-
598-
let expected =
599-
'⚠ Could not verify workflow file at https://gitlab.com/rust-lang/crates.io/-/raw/HEAD/.gitlab-ci.yml (network error)';
600-
assert.dom('[data-test-workflow-verification="error"]').hasText(expected);
601-
});
602-
});
603517
});
604518
});

0 commit comments

Comments
 (0)