feat(utils,types,framework,medusa): store endpoints should require publishable key (#9068)
* feat(utils,types,framework,medusa): store endpoints should require publishable key * chore: fix specs * chore: fix more specs * chore: update js-sdk * chore: fix specs wrt to default SC * chore: revert custom headers + change error message * chore: fix specs * chore: fix new store specs
This commit is contained in:
@@ -5,6 +5,8 @@ import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
import {
|
||||
adminHeaders,
|
||||
createAdminUser,
|
||||
generatePublishableKey,
|
||||
generateStoreHeaders,
|
||||
} from "../../../../helpers/create-admin-user"
|
||||
|
||||
jest.setTimeout(30000)
|
||||
@@ -17,9 +19,13 @@ medusaIntegrationTestRunner({
|
||||
let customer4
|
||||
let customer5
|
||||
let container
|
||||
let storeHeaders
|
||||
|
||||
beforeEach(async () => {
|
||||
container = getContainer()
|
||||
await createAdminUser(dbConnection, adminHeaders, container)
|
||||
const publishableKey = await generatePublishableKey(container)
|
||||
storeHeaders = generateStoreHeaders({ publishableKey })
|
||||
|
||||
customer1 = (
|
||||
await api.post(
|
||||
@@ -415,6 +421,7 @@ medusaIntegrationTestRunner({
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${registeredCustomerToken}`,
|
||||
...storeHeaders.headers,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
@@ -3,6 +3,8 @@ import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
import {
|
||||
adminHeaders,
|
||||
createAdminUser,
|
||||
generatePublishableKey,
|
||||
generateStoreHeaders,
|
||||
} from "../../../../helpers/create-admin-user"
|
||||
|
||||
jest.setTimeout(30000)
|
||||
@@ -10,20 +12,27 @@ jest.setTimeout(30000)
|
||||
medusaIntegrationTestRunner({
|
||||
testSuite: ({ dbConnection, api, getContainer }) => {
|
||||
let appContainer: MedusaContainer
|
||||
let storeHeaders
|
||||
|
||||
beforeEach(async () => {
|
||||
appContainer = getContainer()
|
||||
const publishableKey = await generatePublishableKey(appContainer)
|
||||
storeHeaders = generateStoreHeaders({ publishableKey })
|
||||
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||
})
|
||||
|
||||
describe("POST /admin/customers", () => {
|
||||
describe("POST /store/customers", () => {
|
||||
it("should fails to create a customer without an identity", async () => {
|
||||
const customer = await api
|
||||
.post("/store/customers", {
|
||||
email: "newcustomer@medusa.js",
|
||||
first_name: "John",
|
||||
last_name: "Doe",
|
||||
})
|
||||
.post(
|
||||
"/store/customers",
|
||||
{
|
||||
email: "newcustomer@medusa.js",
|
||||
first_name: "John",
|
||||
last_name: "Doe",
|
||||
},
|
||||
storeHeaders
|
||||
)
|
||||
.catch((e) => e)
|
||||
|
||||
expect(customer.response.status).toEqual(401)
|
||||
@@ -48,6 +57,7 @@ medusaIntegrationTestRunner({
|
||||
{
|
||||
headers: {
|
||||
authorization: `Bearer ${signup.data.token}`,
|
||||
...storeHeaders.headers,
|
||||
},
|
||||
}
|
||||
)
|
||||
@@ -102,6 +112,7 @@ medusaIntegrationTestRunner({
|
||||
{
|
||||
headers: {
|
||||
authorization: `Bearer ${signup.data.token}`,
|
||||
...storeHeaders.headers,
|
||||
},
|
||||
}
|
||||
)
|
||||
@@ -161,6 +172,7 @@ medusaIntegrationTestRunner({
|
||||
{
|
||||
headers: {
|
||||
authorization: `Bearer ${firstSignup.data.token}`,
|
||||
...storeHeaders.headers,
|
||||
},
|
||||
}
|
||||
)
|
||||
@@ -181,6 +193,7 @@ medusaIntegrationTestRunner({
|
||||
{
|
||||
headers: {
|
||||
authorization: `Bearer ${firstSignin.data.token}`,
|
||||
...storeHeaders.headers,
|
||||
},
|
||||
}
|
||||
)
|
||||
@@ -191,6 +204,54 @@ medusaIntegrationTestRunner({
|
||||
"Request already authenticated as a customer."
|
||||
)
|
||||
})
|
||||
|
||||
describe("With ensurePublishableApiKey middleware", () => {
|
||||
it("should fail when no publishable key is passed in the header", async () => {
|
||||
const { response } = await api
|
||||
.post(
|
||||
"/store/customers",
|
||||
{
|
||||
email: "newcustomer@medusa.js",
|
||||
first_name: "John",
|
||||
last_name: "Doe",
|
||||
},
|
||||
{
|
||||
headers: {},
|
||||
}
|
||||
)
|
||||
.catch((e) => e)
|
||||
|
||||
expect(response.data).toEqual({
|
||||
message:
|
||||
"Publishable API key required in the request header: x-publishable-api-key. You can manage your keys in settings in the dashboard.",
|
||||
type: "not_allowed",
|
||||
})
|
||||
})
|
||||
|
||||
it("should fail when publishable keys are invalid", async () => {
|
||||
const { response } = await api
|
||||
.post(
|
||||
"/store/customers",
|
||||
{
|
||||
email: "newcustomer@medusa.js",
|
||||
first_name: "John",
|
||||
last_name: "Doe",
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
"x-publishable-api-key": ["test1", "test2"],
|
||||
},
|
||||
}
|
||||
)
|
||||
.catch((e) => e)
|
||||
|
||||
expect(response.data).toEqual({
|
||||
message:
|
||||
"A valid publishable key is required to proceed with the request",
|
||||
type: "not_allowed",
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user