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
9 changes: 8 additions & 1 deletion hasura/metadata/graphql_schema_introspection.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
disabled_for_roles: []
disabled_for_roles:
- public
- user
- api_key
- reviewer
- qa
- service
- analytics
2 changes: 1 addition & 1 deletion tests/api/jest.setup.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Global setup for API tests - validates required environment variables

const requiredEnvVars = ["INTERNAL_API_URL", "NAME_SLUG"];
const requiredEnvVars = ["INTERNAL_API_URL"];

beforeAll(() => {
const missingEnvVars = requiredEnvVars.filter(
Expand Down
51 changes: 51 additions & 0 deletions tests/api/specs/hasura/graphql-introspection.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import axios from "axios";

describe("GraphQL Introspection", () => {
const hasAdminSecret = Boolean(process.env.HASURA_GRAPHQL_ADMIN_SECRET);

beforeAll(() => {
const requiredEnvVars = ["HASURA_GRAPHQL_URL"];

const missingEnvVars = requiredEnvVars.filter(
(envVar) => !process.env[envVar],
);

if (missingEnvVars.length > 0) {
throw new Error(
`Required environment variables are not set: ${missingEnvVars.join(", ")}`,
);
}
});

it("rejects introspection queries from unauthenticated requests", async () => {
const response = await axios.post(
process.env.HASURA_GRAPHQL_URL!,
{ query: "{ __schema { types { name } } }" },
{
headers: { "Content-Type": "application/json" },
validateStatus: () => true,
},
);
// Hasura returns 200 with an errors array when introspection is disabled
expect(response.data.errors).toBeDefined();
expect(response.data.errors[0].message).toMatch(/introspection/i);
});

(hasAdminSecret ? it : it.skip)(
"allows introspection queries with the admin secret",
async () => {
const response = await axios.post(
process.env.HASURA_GRAPHQL_URL!,
{ query: "{ __schema { types { name } } }" },
{
headers: {
"Content-Type": "application/json",
"x-hasura-admin-secret": process.env.HASURA_GRAPHQL_ADMIN_SECRET!,
},
},
);
expect(response.data.data.__schema).toBeDefined();
expect(response.data.errors).toBeUndefined();
},
);
});
Loading