Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 13 additions & 24 deletions graphql/server-test/__tests__/upload.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* pnpm test -- --testPathPattern=upload.integration
*/

import crypto from 'crypto';
import { hashContent, putToPresignedUrl } from '@constructive-io/upload-client';
import path from 'path';
import { getConnections, seed } from '../src';
import type supertest from 'supertest';
Expand Down Expand Up @@ -199,25 +199,6 @@ const DELETE_APP_BUCKET = `
// Helpers
// =========================================================================

function sha256(content: string): string {
return crypto.createHash('sha256').update(content).digest('hex');
}

async function putToPresignedUrl(
url: string,
content: string,
contentType: string,
): Promise<Response> {
return fetch(url, {
method: 'PUT',
headers: {
'Content-Type': contentType,
'Content-Length': Buffer.byteLength(content).toString(),
},
body: content,
});
}

/**
* Assert that a mutation was denied specifically by RLS (not by some other error).
*
Expand Down Expand Up @@ -351,9 +332,13 @@ describe('Integration tests (uploads, tenant isolation, RLS)', () => {
describe('Public file upload', () => {
const fileContent = 'Hello, public world!';
const contentType = 'text/plain';
const contentHash = sha256(fileContent);
let contentHash: string;
let uploadUrl: string;

beforeAll(async () => {
contentHash = await hashContent(fileContent);
});

it('should return a presigned PUT URL via uploadAppFile', async () => {
const res = await postGraphQL({
query: UPLOAD_APP_FILE,
Expand Down Expand Up @@ -389,9 +374,13 @@ describe('Integration tests (uploads, tenant isolation, RLS)', () => {
describe('Private file upload', () => {
const fileContent = 'Hello, private world!';
const contentType = 'text/plain';
const contentHash = sha256(fileContent);
let contentHash: string;
let uploadUrl: string;

beforeAll(async () => {
contentHash = await hashContent(fileContent);
});

it('should return a presigned PUT URL via uploadAppFile', async () => {
const res = await postGraphQL({
query: UPLOAD_APP_FILE,
Expand Down Expand Up @@ -427,7 +416,7 @@ describe('Integration tests (uploads, tenant isolation, RLS)', () => {
describe('Deduplication', () => {
it('should return deduplicated=true for an existing content hash', async () => {
const fileContent = 'Hello, public world!';
const contentHash = sha256(fileContent);
const contentHash = await hashContent(fileContent);

const res = await postGraphQL({
query: UPLOAD_APP_FILE,
Expand Down Expand Up @@ -510,7 +499,7 @@ describe('Integration tests (uploads, tenant isolation, RLS)', () => {
describe('Three-way tenant isolation (Alice, Bob, Mallory)', () => {
it('Bob uploads a file via his primary API', async () => {
const fileContent = 'Bob secret data';
const contentHash = sha256(fileContent);
const contentHash = await hashContent(fileContent);

const res = await postGraphQLViaApi(bobDatabaseId, 'bob-app', {
query: UPLOAD_APP_FILE,
Expand Down
1 change: 1 addition & 0 deletions graphql/server-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"@constructive-io/graphql-env": "workspace:^",
"@constructive-io/graphql-server": "workspace:^",
"@constructive-io/graphql-types": "workspace:^",
"@constructive-io/upload-client": "workspace:*",
"@pgpmjs/types": "workspace:^",
"express": "^5.2.1",
"graphile-schema": "workspace:^",
Expand Down
Loading
Loading