Skip to content

Commit

Permalink
revert: process.env -> Bun.env to see if tests are fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Creaous committed Dec 8, 2024
1 parent 1704571 commit 1834401
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 25 deletions.
4 changes: 2 additions & 2 deletions drizzle/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import { sql } from 'drizzle-orm';

const migrationsFolder = process.argv[2] ?? '../drizzle';

console.log(Bun.env.DATABASE_URL);
console.log(process.env.DATABASE_URL);

export const dbClient = new Client({
connectionString: Bun.env.DATABASE_URL as string
connectionString: process.env.DATABASE_URL as string
});

const db = drizzle(dbClient);
Expand Down
8 changes: 4 additions & 4 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { tokenClient } from './redis';
namespace Config {
export const OpenID: OIDCPluginOptionsBase = {
oidc: new OIDC({
introspect_url: Bun.env.AUTH_INTROSPECT_URL!,
userinfo_url: Bun.env.AUTH_USERINFO_URL,
client_id: Bun.env.AUTH_CLIENT_ID,
client_secret: Bun.env.AUTH_CLIENT_SECRET
introspect_url: process.env.AUTH_INTROSPECT_URL!,
userinfo_url: process.env.AUTH_USERINFO_URL,
client_id: process.env.AUTH_CLIENT_ID,
client_secret: process.env.AUTH_CLIENT_SECRET
}),
redis: tokenClient,
messages: {
Expand Down
4 changes: 2 additions & 2 deletions src/drizzle/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Client as prodClient } from 'pg'; // for production use
import * as schema from './schema'; // get all the schema

export const prodDbClient = new prodClient({
connectionString: Bun.env.DATABASE_URL as string
connectionString: process.env.DATABASE_URL as string
});

import { NodePgDatabase } from 'drizzle-orm/node-postgres';
Expand All @@ -13,7 +13,7 @@ let db:
| (NodePgDatabase<typeof schema> & { $client: prodClient })
| (PgliteDatabase<typeof schema> & { $client: any });

if (Bun.env.NODE_ENV !== 'test') {
if (process.env.NODE_ENV !== 'test') {
db = prodDrizzle(prodDbClient, { schema }); // we want to use a real database
} else {
import('@electric-sql/pglite').then(({ PGlite: testClient }) => {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/authentik.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('getHashedPk', () => {

test('should return hashed version of user ID', () => {
const hashedPk = createHash('sha256')
.update(pk1 + '-' + Bun.env.AUTH_INSTALLATION_ID)
.update(pk1 + '-' + process.env.AUTH_INSTALLATION_ID)
.digest('hex');
const result = getHashedPk(pk1);
expect(result).toBe(hashedPk);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/authentik.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export function convertModelToUser(jsonObject: { body: string }) {
*/
export function getHashedPk(pk: string) {
const hashedPk = createHash('sha256')
.update(pk + '-' + Bun.env.AUTH_INSTALLATION_ID)
.update(pk + '-' + process.env.AUTH_INSTALLATION_ID)
.digest('hex');
return hashedPk;
}
26 changes: 15 additions & 11 deletions src/lib/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ async function mediaUploadEndpoint(req: Request) {

// Generate a predicted key for the S3 upload.
const s3PredictedKey =
Bun.env.S3_UPLOAD_DIR! +
process.env.S3_UPLOAD_DIR! +
'/' +
possibleUUID +
'.' +
Expand All @@ -126,15 +126,15 @@ async function mediaUploadEndpoint(req: Request) {
new Upload({
client: new S3Client({
credentials: {
accessKeyId: Bun.env.AWS_ACCESS_KEY_ID!,
secretAccessKey: Bun.env.AWS_SECRET_ACCESS_KEY!
accessKeyId: process.env.AWS_ACCESS_KEY_ID!,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY!
},
region: Bun.env.S3_REGION!,
endpoint: Bun.env.AWS_ENDPOINT!
region: process.env.S3_REGION!,
endpoint: process.env.AWS_ENDPOINT!
}),
params: {
ACL: 'public-read',
Bucket: Bun.env.S3_BUCKET!,
Bucket: process.env.S3_BUCKET!,
Key: s3PredictedKey,
Body: media
}
Expand Down Expand Up @@ -173,14 +173,16 @@ async function webhookEndpoint(req: Request) {
const url = new URL(req.url);
console.log(url.pathname, isTestMode);
switch (url.pathname) {
case `/webhook/${isTestMode ? 'TEST-AUTH' : Bun.env.WEBHOOK_AUTH}`:
case `/webhook/${isTestMode ? 'TEST-AUTH' : process.env.WEBHOOK_AUTH}`:
if (
isTestMode ||
(Bun.env.AUTH_INTROSPECT_URL?.endsWith(
(process.env.AUTH_INTROSPECT_URL?.endsWith(
'/application/o/introspect/'
) &&
isTestMode) ||
Bun.env.AUTH_USERINFO_URL?.endsWith('/application/o/userinfo/')
process.env.AUTH_USERINFO_URL?.endsWith(
'/application/o/userinfo/'
)
) {
// Convert the request body to JSON and sort it.
var json = await req.json();
Expand Down Expand Up @@ -265,7 +267,9 @@ async function webhookEndpoint(req: Request) {
},
{ status: 404 }
);
case `/webhook/${isTestMode ? 'TEST-STRIPE' : Bun.env.WEBHOOK_STRIPE}`:
case `/webhook/${
isTestMode ? 'TEST-STRIPE' : process.env.WEBHOOK_STRIPE
}`:
return Response.json(
{
status: 'WORK_IN_PROGRESS',
Expand Down Expand Up @@ -364,7 +368,7 @@ async function createUsersFromRedisTokens() {
}

// Just a shortcut for checking if we are in test mode.
const isTestMode = Bun.env.NODE_ENV === 'test';
const isTestMode = process.env.NODE_ENV === 'test';

export {
createUsersFromRedisTokens,
Expand Down
4 changes: 3 additions & 1 deletion src/redis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ if (isTestMode) {

// Create a Redis client using the createClient function.
export const redisClient = createClient({
url: !isTestMode ? (Bun.env.REDIS_URL as string) : 'redis://localhost:1234'
url: !isTestMode
? (process.env.REDIS_URL as string)
: 'redis://localhost:1234'
});

// Create a new Redis client just for tokens using the duplicate method.
Expand Down
6 changes: 3 additions & 3 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ export async function startServer() {
}
}
}),
port: isTestMode ? 25447 : Bun.env.PORT ?? 3000,
development: !!(Bun.env.NODE_ENV === 'development') || isTestMode
port: isTestMode ? 25447 : process.env.PORT ?? 3000,
development: !!(process.env.NODE_ENV === 'development') || isTestMode
});

// Connect to Redis.
Expand Down Expand Up @@ -155,7 +155,7 @@ export async function startServer() {
if (!isTestMode) {
console.log(
`🔑 Authentication Server: ${
new URL(Bun.env.AUTH_INTROSPECT_URL!).hostname
new URL(process.env.AUTH_INTROSPECT_URL!).hostname
}`
);
} else {
Expand Down

0 comments on commit 1834401

Please sign in to comment.