-
Notifications
You must be signed in to change notification settings - Fork 2
test: deepen safe file and transfer live fixtures #182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ac00fb8
test: deepen safe file and transfer live fixtures
altaywtf 47d34aa
test: standardize live fixture identity
altaywtf f069f6f
fix(tests): address live harness review findings
altaywtf a6374c1
fix(tests): close live runner safety gaps
altaywtf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| /.env | ||
| /.env.live-tokens | ||
| /.env.local |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises"; | ||
| import { tmpdir } from "node:os"; | ||
| import { join } from "node:path"; | ||
|
|
||
| import { describe, expect, it } from "vite-plus/test"; | ||
|
|
||
| import { resolveLiveTestTargets } from "./live-targets.ts"; | ||
|
|
||
| describe("resolveLiveTestTargets", () => { | ||
| it("accepts relative and absolute paths under test/live", async () => { | ||
| const cwd = await mkdtemp(join(tmpdir(), "putio-sdk-live-targets-")); | ||
| const target = join(cwd, "test/live/files.test.ts"); | ||
|
|
||
| try { | ||
| await mkdir(join(cwd, "test/live"), { recursive: true }); | ||
| await writeFile(target, ""); | ||
|
|
||
| expect(resolveLiveTestTargets(["./test/live/files.test.ts", target], cwd)).toEqual([ | ||
| target, | ||
| target, | ||
| ]); | ||
| } finally { | ||
| await rm(cwd, { force: true, recursive: true }); | ||
| } | ||
| }); | ||
|
|
||
| it("rejects test files outside test/live", async () => { | ||
| const cwd = await mkdtemp(join(tmpdir(), "putio-sdk-live-targets-")); | ||
| const target = join(cwd, "test/files.test.ts"); | ||
|
|
||
| try { | ||
| await mkdir(join(cwd, "test"), { recursive: true }); | ||
| await writeFile(target, ""); | ||
|
|
||
| expect(() => resolveLiveTestTargets([target], cwd)).toThrow( | ||
| `Unsupported live test target: ${target}`, | ||
| ); | ||
| } finally { | ||
| await rm(cwd, { force: true, recursive: true }); | ||
| } | ||
| }); | ||
|
|
||
| it("rejects targets that log in with account credentials", async () => { | ||
| const cwd = await mkdtemp(join(tmpdir(), "putio-sdk-live-targets-")); | ||
| const target = join(cwd, "test/live/podcast.test.ts"); | ||
|
|
||
| try { | ||
| await mkdir(join(cwd, "test/live"), { recursive: true }); | ||
| await writeFile(target, ""); | ||
|
|
||
| expect(() => resolveLiveTestTargets([target], cwd)).toThrow( | ||
| `Credential-backed target is not allowed: ${target}`, | ||
| ); | ||
| } finally { | ||
| await rm(cwd, { force: true, recursive: true }); | ||
| } | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import { existsSync } from "node:fs"; | ||
| import { isAbsolute, relative, resolve, sep } from "node:path"; | ||
|
|
||
| const CREDENTIAL_BACKED_TARGETS = new Set([ | ||
| "auth-credentials.test.ts", | ||
| "family.test.ts", | ||
| "friend-invites.test.ts", | ||
| "friends.test.ts", | ||
| "podcast.test.ts", | ||
| "sharing.test.ts", | ||
| ]); | ||
|
|
||
| export const resolveLiveTestTargets = ( | ||
| targets: ReadonlyArray<string>, | ||
| cwd = process.cwd(), | ||
| ): ReadonlyArray<string> => { | ||
| const liveRoot = resolve(cwd, "test/live"); | ||
|
|
||
| return targets.map((target) => { | ||
| const resolvedTarget = resolve(cwd, target); | ||
| const relativeTarget = relative(liveRoot, resolvedTarget); | ||
| const isLiveTest = | ||
| relativeTarget.endsWith(".test.ts") && | ||
| relativeTarget !== ".." && | ||
| !relativeTarget.startsWith(`..${sep}`) && | ||
| !isAbsolute(relativeTarget); | ||
|
|
||
| if (!isLiveTest || !existsSync(resolvedTarget)) { | ||
| throw new Error(`Unsupported live test target: ${target}`); | ||
| } | ||
|
|
||
| if (CREDENTIAL_BACKED_TARGETS.has(relativeTarget)) { | ||
| throw new Error(`Credential-backed target is not allowed: ${target}`); | ||
| } | ||
|
|
||
| return resolvedTarget; | ||
| }); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import { mkdtemp, readFile, rm, stat } from "node:fs/promises"; | ||
| import { tmpdir } from "node:os"; | ||
| import { join } from "node:path"; | ||
| import { pathToFileURL } from "node:url"; | ||
|
|
||
| import { describe, expect, it } from "vite-plus/test"; | ||
|
|
||
| import { writeLiveTokenCache } from "./live-token-cache.ts"; | ||
|
|
||
| describe("live token cache", () => { | ||
| it("writes dotenv tokens with 0600 permissions", async () => { | ||
| const directory = await mkdtemp(join(tmpdir(), "putio-sdk-live-tokens-")); | ||
| try { | ||
| const url = pathToFileURL(join(directory, ".env.live-tokens")); | ||
| await writeLiveTokenCache(url, { | ||
| firstPartyToken: "first-test-token", | ||
| thirdPartyToken: "third-test-token", | ||
| }); | ||
|
|
||
| expect(await readFile(url, "utf8")).toBe( | ||
| 'PUTIO_TOKEN_FIRST_PARTY="first-test-token"\n' + | ||
| 'PUTIO_TOKEN_THIRD_PARTY="third-test-token"\n', | ||
| ); | ||
| expect((await stat(url)).mode & 0o777).toBe(0o600); | ||
| } finally { | ||
| await rm(directory, { force: true, recursive: true }); | ||
| } | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { chmod, writeFile } from "node:fs/promises"; | ||
|
|
||
| export const liveTokenCacheUrl = new URL("../.env.live-tokens", import.meta.url); | ||
|
altaywtf marked this conversation as resolved.
|
||
|
|
||
| export const writeLiveTokenCache = async ( | ||
| url: URL, | ||
| tokens: { | ||
| readonly firstPartyToken: string; | ||
| readonly thirdPartyToken: string; | ||
| }, | ||
| ): Promise<void> => { | ||
| const contents = [ | ||
| `PUTIO_TOKEN_FIRST_PARTY=${JSON.stringify(tokens.firstPartyToken)}`, | ||
| `PUTIO_TOKEN_THIRD_PARTY=${JSON.stringify(tokens.thirdPartyToken)}`, | ||
| "", | ||
| ].join("\n"); | ||
|
|
||
| await writeFile(url, contents, { mode: 0o600 }); | ||
| await chmod(url, 0o600); | ||
| }; | ||
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.