budibase/packages/backend-core/tests/utilities/testEnv.ts

88 lines
3.1 KiB
TypeScript
Raw Normal View History

import env from "../../src/environment"
import * as tenancy from "../../src/tenancy"
import { newid } from "../../src/utils"
// TENANCY
export async function withTenant(task: (tenantId: string) => any) {
const tenantId = newid()
return tenancy.doInTenant(tenantId, async () => {
await task(tenantId)
})
}
export function singleTenant() {
env._set("MULTI_TENANCY", 0)
}
export function multiTenant() {
env._set("MULTI_TENANCY", 1)
}
// NODE
export function nodeDev() {
env._set("NODE_ENV", "dev")
}
export function nodeJest() {
env._set("NODE_ENV", "jest")
}
// FILES
export function withS3() {
env._set("NODE_ENV", "production")
env._set("MINIO_ENABLED", 0)
env._set("MINIO_URL", "http://s3.example.com")
env._set("CLOUDFRONT_CDN", undefined)
}
const CLOUDFRONT_TEST_KEY =
"-----BEGIN RSA PRIVATE KEY-----\n" +
"MIIEpAIBAAKCAQEAqXRsir/0Qba1xEnybUs7d7QEAE02GRc+4H7HD5l5VnAxkV1m\n" +
"tNTXTmoYkaIhLdebV1EwQs3T9knxoyd4cVcrDkDfDLZErfYWJsuE3/QYNknnZs4/\n" +
"Ai0cg+v9ZX3gcizvpYg9GQI3INM0uRG8lJwGP7FQ/kknhA2yVFVCSxX6kkNtOUh5\n" +
"dKSG7m6IwswcSwD++Z/94vsFkoZIGY0e1CD/drFJ6+1TFY2YgbDKT5wDFLJ9vHFx\n" +
"/5o4POwn3gz/ru2Db9jbRdfEAqRdy46nRKQgBGUmupAgSK1+BJEzafexp8RmCGb0\n" +
"WUffxOtj8/jNCeCF0JBgVHAe3crOQ8ySrtoaHQIDAQABAoIBAA+ipW07/u6dTDI7\n" +
"XHoHKgqGeqQIe8he47dVG0ruL0rxeTFfe92NkfwzP+cYHZWcQkIRRLG1Six8cCZM\n" +
"uwlCML/U7n++xaGDhlG4D5+WZzGDKi3LM/cgcHQfrzbRIYeHa+lLI9AN60ZFFqVI\n" +
"5KyVpOH1m3KLD3FYzi6H22EQOxmJpqWlt2uArny5LxlP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\n" +
"ifMbhZslFThC/osD5ZV7snXZgTWyPexaINJhHmdrAWpmW1h+UFoiMw==\n" +
"-----END RSA PRIVATE KEY-----\n"
const CLOUDFRONT_TEST_KEY_64 = Buffer.from(
CLOUDFRONT_TEST_KEY,
"utf-8"
).toString("base64")
export function withCloudfront() {
withS3()
env._set("CLOUDFRONT_CDN", "http://cf.example.com")
env._set("CLOUDFRONT_PUBLIC_KEY_ID", "keypair_123")
env._set("CLOUDFRONT_PRIVATE_KEY_64", CLOUDFRONT_TEST_KEY_64)
}
export function withMinio() {
env._set("NODE_ENV", "production")
env._set("MINIO_ENABLED", 1)
env._set("MINIO_URL", "http://minio.example.com")
env._set("CLOUDFRONT_CDN", undefined)
}