From 698cb06dd118ea350aa6085ba4013a5152c84b62 Mon Sep 17 00:00:00 2001 From: Arne Luenser Date: Mon, 24 Jun 2024 12:41:23 +0200 Subject: [PATCH] feat: fix e2e --- go.mod | 2 +- go.sum | 2 + package-lock.json | 96 +++++++++++++++++++++++++++++++++++++++++++++ package.json | 1 + tests/login.spec.ts | 39 +++++++++++++++--- 5 files changed, 134 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 270dd09e..ff4f55a0 100644 --- a/go.mod +++ b/go.mod @@ -37,7 +37,7 @@ require ( github.com/ory/hydra-client-go/v2 v2.2.0-rc.3.0.20240202131107-1c7b57df3bb0 github.com/ory/hydra/v2 v2.2.0-pre.1 github.com/ory/jsonschema/v3 v3.0.8 - github.com/ory/keto v0.11.1-alpha.0.0.20231228131228-b2c3464bdc4f + github.com/ory/keto v0.13.0-alpha.0.0.20240624092507-567ceb9144b0 github.com/ory/kratos v1.1.0-pre.0.0.20240205165553-fd7995077307 github.com/ory/x v0.0.613 github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 diff --git a/go.sum b/go.sum index 02bdea93..8127d1bc 100644 --- a/go.sum +++ b/go.sum @@ -902,6 +902,8 @@ github.com/ory/hydra/v2 v2.2.0-pre.1 h1:+VzGZ6AtiajgTq0I5m2nYvEX0l+I/nIci5kTuVA/ github.com/ory/hydra/v2 v2.2.0-pre.1/go.mod h1:yQRtYAxtGOD41QakuLLI9GVO9BUQzL5ShAxikGZPQbA= github.com/ory/jsonschema/v3 v3.0.8 h1:Ssdb3eJ4lDZ/+XnGkvQS/te0p+EkolqwTsDOCxr/FmU= github.com/ory/jsonschema/v3 v3.0.8/go.mod h1:ZPzqjDkwd3QTnb2Z6PAS+OTvBE2x5i6m25wCGx54W/0= +github.com/ory/keto v0.13.0-alpha.0.0.20240624092507-567ceb9144b0 h1:lsBYI6FsW+DQSzTld2fiC4bC8ELOfGrbARqguomWIqk= +github.com/ory/keto v0.13.0-alpha.0.0.20240624092507-567ceb9144b0/go.mod h1:NXGcNJ65ocZG5mvUCtoDHW53tA2MNoK2iQL7L0UDaGs= github.com/ory/keto/proto v0.11.1-alpha.0.0.20231229091411-ac44cabd79b7 h1:qHgWDFJ642DUYj7fMUs7pRTqr1oM7Hqw26qnxB9lvlk= github.com/ory/keto/proto v0.11.1-alpha.0.0.20231229091411-ac44cabd79b7/go.mod h1:6RagCXA7X1hhFSVjcy13ruIo8Dq/nj4J0mcN92qL+hY= github.com/ory/kratos v1.1.0-pre.0.0.20240205165553-fd7995077307 h1:GM/UJdUQY+t42wmo/6gcrqqr/BwwZI/NpyAirQtcppQ= diff --git a/package-lock.json b/package-lock.json index bdafea26..bc9f66a2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "0.0.85", "hasInstallScript": true, "dependencies": { + "@ory/client": "^1.11.11", "binwrap": "^0.2.3" }, "bin": { @@ -120,6 +121,14 @@ "node": ">= 8" } }, + "node_modules/@ory/client": { + "version": "1.11.11", + "resolved": "https://registry.npmjs.org/@ory/client/-/client-1.11.11.tgz", + "integrity": "sha512-HcAUikeLOj6XfNrohowHs0hv47k5sQ8I3gMy9914+wsTNRONRZdKJYf80AaiEUWyzGfpun9BebfjJU9YfLvP0w==", + "dependencies": { + "axios": "^1.6.1" + } + }, "node_modules/@panva/asn1.js": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/@panva/asn1.js/-/asn1.js-1.0.0.tgz", @@ -464,6 +473,34 @@ "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.11.0.tgz", "integrity": "sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA==" }, + "node_modules/axios": { + "version": "1.7.2", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.2.tgz", + "integrity": "sha512-2A8QhOMrbomlDuiLeK9XibIBzuHeRcqqNOHp0Cyp5EoJ1IFDh+XZH3A6BkXtv0K4gFGCI0Y4BM7B1wOEi0Rmgw==", + "dependencies": { + "follow-redirects": "^1.15.6", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + } + }, + "node_modules/axios/node_modules/form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/axios/node_modules/proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" + }, "node_modules/balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", @@ -1235,6 +1272,25 @@ "node": ">=8" } }, + "node_modules/follow-redirects": { + "version": "1.15.6", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz", + "integrity": "sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==", + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/RubenVerborgh" + } + ], + "engines": { + "node": ">=4.0" + }, + "peerDependenciesMeta": { + "debug": { + "optional": true + } + } + }, "node_modules/forever-agent": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz", @@ -3935,6 +3991,14 @@ "fastq": "^1.6.0" } }, + "@ory/client": { + "version": "1.11.11", + "resolved": "https://registry.npmjs.org/@ory/client/-/client-1.11.11.tgz", + "integrity": "sha512-HcAUikeLOj6XfNrohowHs0hv47k5sQ8I3gMy9914+wsTNRONRZdKJYf80AaiEUWyzGfpun9BebfjJU9YfLvP0w==", + "requires": { + "axios": "^1.6.1" + } + }, "@panva/asn1.js": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/@panva/asn1.js/-/asn1.js-1.0.0.tgz", @@ -4213,6 +4277,33 @@ "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.11.0.tgz", "integrity": "sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA==" }, + "axios": { + "version": "1.7.2", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.2.tgz", + "integrity": "sha512-2A8QhOMrbomlDuiLeK9XibIBzuHeRcqqNOHp0Cyp5EoJ1IFDh+XZH3A6BkXtv0K4gFGCI0Y4BM7B1wOEi0Rmgw==", + "requires": { + "follow-redirects": "^1.15.6", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + }, + "dependencies": { + "form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "requires": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + } + }, + "proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" + } + } + }, "balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", @@ -4822,6 +4913,11 @@ "to-regex-range": "^5.0.1" } }, + "follow-redirects": { + "version": "1.15.6", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz", + "integrity": "sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==" + }, "forever-agent": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz", diff --git a/package.json b/package.json index f1952eed..4362e2d9 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ }, "prettier": "ory-prettier-styles", "dependencies": { + "@ory/client": "^1.11.11", "binwrap": "^0.2.3" }, "devDependencies": { diff --git a/tests/login.spec.ts b/tests/login.spec.ts index 50afdec8..e239aeb1 100644 --- a/tests/login.spec.ts +++ b/tests/login.spec.ts @@ -3,6 +3,7 @@ import { ChildProcessWithoutNullStreams, spawn } from "child_process" import { randomBytes } from "crypto" import { unlink } from "fs/promises" import readline from "node:readline/promises" +import * as sdk from "@ory/client" function generateRandomFileName(extension: string): string { const randomString = randomBytes(16).toString("hex") @@ -10,12 +11,40 @@ function generateRandomFileName(extension: string): string { } test.describe("should be able to login with the CLI", () => { + const email = `${randomBytes(16).toString("hex")}@example.com` + const password = randomBytes(16).toString("hex") const config = generateRandomFileName(".cli-config.json") let url: string = "" - let child: ChildProcessWithoutNullStreams + let child: ChildProcessWithoutNullStreams | undefined let rl: readline.Interface test.beforeAll(async () => { + const ory = new sdk.FrontendApi( + new sdk.Configuration({ + basePath: "https://project.console.ory:8080", + }), + ) + + const { + data: { id: flowID }, + } = await ory.createNativeRegistrationFlow() + const res = await ory.updateRegistrationFlow({ + flow: flowID, + updateRegistrationFlowBody: { + method: "password", + password, + traits: { + email, + name: "John Doe", + consent: { + newsletter: false, + tos: new Date().toISOString(), + }, + }, + }, + }) + expect(res.status).toBe(200) + child = spawn("./cli", ["auth"], { env: { HOME: "/dev/null", @@ -44,8 +73,8 @@ test.describe("should be able to login with the CLI", () => { }) test.afterAll(async () => { - child.kill() - await unlink(config) + child?.kill() + await unlink(config).catch(() => {}) }) test("with email and password", async ({ page }) => { @@ -53,11 +82,11 @@ test.describe("should be able to login with the CLI", () => { const emailInput = await page.locator( `[data-testid="node/input/identifier"] input`, ) - await emailInput.fill("") + await emailInput.fill(email) const passwordInput = await page.locator( `[data-testid="node/input/password"] input`, ) - await passwordInput.fill("") + await passwordInput.fill(password) const submit = page.locator( '[type="submit"][name="method"][value="password"]', )