Skip to content

Commit

Permalink
asd
Browse files Browse the repository at this point in the history
  • Loading branch information
dbarrosop committed Feb 11, 2024
1 parent eb381b5 commit 23acd90
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 24 deletions.
23 changes: 19 additions & 4 deletions build/dev/docker/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,23 +1,38 @@
version: "3.8"
services:
auth:
image: nhost/hasura-auth:0.22.0
image: nhost/hasura-auth:0.0.0-dev
# image: nhost/hasura-auth:0.25.0
command: serve
depends_on:
graphql:
condition: service_healthy
postgres:
condition: service_healthy
ports:
- mode: ingress
target: 4000
published: "4000"
protocol: tcp
environment:
NODE_ENV: development
AUTH_API_PREFIX: ""
HASURA_GRAPHQL_DATABASE_URL: "postgres://postgres:postgres@127.0.0.1:5432/local"
POSTGRES_CONNECTION: "postgres://postgres:postgres@127.0.0.1:5432/local"
HASURA_GRAPHQL_DATABASE_URL: "postgres://postgres:postgres@postgres:5432/local"
HASURA_GRAPHQL_JWT_SECRET: '{"type":"HS256", "key":"5152fa850c02dc222631cca898ed1485821a70912a6e3649c49076912daa3b62182ba013315915d64f40cddfbb8b58eb5bd11ba225336a6af45bbae07ca873f3","issuer":"hasura-auth"}'
HASURA_GRAPHQL_ADMIN_SECRET: nhost-admin-secret
HASURA_GRAPHQL_GRAPHQL_URL: http://127.0.0.1:8080/v1/graphql
HASURA_GRAPHQL_GRAPHQL_URL: http://graphql:8080/v1/graphql
AUTH_PORT: 4000
AUTH_SERVER_URL: http://127.0.0.2:4000
AUTH_USER_DEFAULT_ALLOWED_ROLES: 'me,user,editor'
AUTH_SMTP_AUTH_METHOD: LOGIN
AUTH_SMTP_HOST: mailhog
AUTH_SMTP_PASS: password
AUTH_SMTP_PORT: "1025"
AUTH_SMTP_SECURE: "false"
AUTH_SMTP_SENDER: hasura-auth@example.com
AUTH_SMTP_USER: user
AUTH_LOG_LEVEL: debug
AUTH_CLIENT_URL: 'http://localhost:3000'
healthcheck:
test:
- CMD
Expand Down
27 changes: 20 additions & 7 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@
];
};

node_modules = pkgs.stdenv.mkDerivation {
node_modules-builder = pkgs.stdenv.mkDerivation {
inherit version;

pname = "node_modules";
pname = "node_modules-builder";

nativeBuildInputs = with pkgs; [
nodePackages.pnpm
Expand All @@ -80,7 +80,7 @@
};

buildPhase = ''
pnpm install
pnpm install --frozen-lockfile
'';

installPhase = ''
Expand All @@ -89,6 +89,14 @@
'';
};

node_modules-prod = node_modules-builder.overrideAttrs (oldAttrs: {
name = "node_modules-prod";

buildPhase = ''
pnpm install --frozen-lockfile --prod
'';
});


name = "hasura-auth";
description = "Nhost's Auth Service";
Expand Down Expand Up @@ -154,13 +162,17 @@
pname = "node-${name}";

buildInputs = with pkgs; [
pkgs.nodejs-slim_18
];

nativeBuildInputs = with pkgs; [
nodePackages.pnpm
];

src = node-src;

buildPhase = ''
ln -s ${node_modules}/node_modules node_modules
ln -s ${node_modules-builder}/node_modules node_modules
pnpm build
'';

Expand All @@ -170,8 +182,7 @@
cp -r migrations $out/migrations
cp -r email-templates $out/email-templates
cp package.json $out/package.json
ln -s ${node_modules}/node_modules $out/node_modules
ln -sf ${pkgs.nodePackages.pnpm}/bin/pnpm $out/bin/pnpm
ln -s ${node_modules-prod}/node_modules $out/node_modules
'';
};

Expand All @@ -183,7 +194,9 @@
] ++ buildInputs;

postInstall = ''
wrapProgram $out/bin/hasura-auth --suffix PATH : ${node-auth}/bin/pnpm
wrapProgram $out/bin/hasura-auth \
--suffix PATH : ${pkgs.nodejs-slim_18}/bin \
--prefix NODE_SERVER_PATH : ${node-auth}
'';
};

Expand Down
16 changes: 10 additions & 6 deletions go/cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,21 +85,25 @@ func CommandServe() *cli.Command {
}
}

func getNodeServer(ctx context.Context, nodeServerPath string, port int) *exec.Cmd {
func getNodeServer(cCtx *cli.Context) *exec.Cmd {
env := os.Environ()
found := false
authPort := strconv.Itoa(cCtx.Int(flagPort) + 1)
for i, v := range env {
if strings.HasPrefix(v, "AUTH_PORT=") {
found = true
env[i] = "AUTH_PORT=" + strconv.Itoa(port+1)
env[i] = "AUTH_PORT=" + authPort
}
}
if !found {
env = append(env, "AUTH_PORT="+strconv.Itoa(port+1))
env = append(env, "AUTH_PORT="+authPort)
}
env = append(env, "NODE_EXTRA_CA_CERTS=/etc/ssl/certs/ca-bundle.crt")
env = append(env, "PWD="+cCtx.String(flagNodeServerPath))
env = append(env, "AUTH_VERSION="+cCtx.App.Version)

cmd := exec.CommandContext(ctx, "pnpm", "start")
cmd.Dir = nodeServerPath
cmd := exec.CommandContext(cCtx.Context, "node", "./dist/start.js")
cmd.Dir = cCtx.String(flagNodeServerPath)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Env = env
Expand Down Expand Up @@ -166,7 +170,7 @@ func serve(cCtx *cli.Context) error {
ctx, cancel := context.WithCancel(cCtx.Context)
defer cancel()

nodeServer := getNodeServer(ctx, cCtx.String(flagNodeServerPath), cCtx.Int(flagPort))
nodeServer := getNodeServer(cCtx)
go func() {
defer cancel()
if err := nodeServer.Run(); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion src/openapi/responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,5 @@ export const UnauthorizedErrorModel = Joi.object<ErrorPayload>({
}).meta({ className: 'UnauthorizedError' });

export const VersionModel = Joi.string()
.example(process.env.npm_package_version)
.example(process.env.AUTH_VERSION)
.meta({ className: 'Version' });
6 changes: 4 additions & 2 deletions test/routes/misc/custom-claims.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as faker from 'faker';
import { patchMetadata } from '@/utils';
import { escapeValueToPg, ENV } from '@/utils';

import { request } from '../../server';
import { request, resetEnvironment } from '../../server';
import { decodeAccessToken } from '../../utils';

describe('custom JWT claims', () => {
Expand All @@ -13,6 +13,8 @@ describe('custom JWT claims', () => {
const projects = [...Array(3).keys()].map(faker.datatype.uuid);

beforeAll(async () => {
await resetEnvironment();

client = new Client({
connectionString: ENV.HASURA_GRAPHQL_DATABASE_URL,
});
Expand All @@ -21,7 +23,7 @@ describe('custom JWT claims', () => {
await client.query(`
CREATE TABLE IF NOT EXISTS public.profiles (
id uuid PRIMARY KEY
CONSTRAINT fk_user REFERENCES auth.users(id)
CONSTRAINT fk_user REFERENCES auth.users(id)
ON UPDATE CASCADE ON DELETE CASCADE,
organisation_id uuid);
CREATE TABLE public.organisations (id uuid primary key default gen_random_uuid());
Expand Down
3 changes: 2 additions & 1 deletion test/routes/misc/tokens.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import { StatusCodes } from 'http-status-codes';
import { Client } from 'pg';

import { ENV } from '../../../src/utils/env';
import { request } from '../../server';
import { request, resetEnvironment } from '../../server';
import { isValidAccessToken } from '../../utils';

describe('token', () => {
let client: Client;

beforeAll(async () => {
await resetEnvironment();
client = new Client({
connectionString: ENV.HASURA_GRAPHQL_DATABASE_URL,
});
Expand Down
4 changes: 3 additions & 1 deletion test/routes/signin/passwordless/email.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { StatusCodes } from 'http-status-codes';
import { Client } from 'pg';
import rfc2047 from 'rfc2047';
import { ENV } from '../../../../src/utils/env';
import { request } from '../../../server';
import { request, resetEnvironment } from '../../../server';
import {
deleteAllMailHogEmails,
expectUrlParameters,
Expand All @@ -14,6 +14,8 @@ describe('passwordless email (magic link)', () => {
let client: Client;

beforeAll(async () => {
await resetEnvironment();

client = new Client({
connectionString: ENV.HASURA_GRAPHQL_DATABASE_URL,
});
Expand Down
4 changes: 2 additions & 2 deletions test/routes/user/deanonymize.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ describe('email-password', () => {
it('should fail to deanonymize user with already existing email', async () => {
// set env vars
await request.post('/change-env').send({
DISABLE_NEW_USERS: false,
ANONYMOUS_USERS_ENABLED: true,
AUTH_DISABLE_NEW_USERS: false,
AUTH_ANONYMOUS_USERS_ENABLED: true,
});

const email = 'joedoe@example.com';
Expand Down

0 comments on commit 23acd90

Please sign in to comment.