-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): Prevent data leakage of guest Customer data
Fixes #98
- Loading branch information
1 parent
ec345be
commit ea51000
Showing
7 changed files
with
185 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ import { | |
GetActiveOrderPayments, | ||
GetAvailableCountries, | ||
GetCustomerAddresses, | ||
GetCustomerOrders, | ||
GetNextOrderStates, | ||
GetOrderByCode, | ||
GetShippingMethods, | ||
|
@@ -49,6 +50,7 @@ import { | |
ADJUST_ITEM_QUANTITY, | ||
GET_ACTIVE_ORDER, | ||
GET_ACTIVE_ORDER_ADDRESSES, | ||
GET_ACTIVE_ORDER_ORDERS, | ||
GET_ACTIVE_ORDER_PAYMENTS, | ||
GET_AVAILABLE_COUNTRIES, | ||
GET_ELIGIBLE_SHIPPING_METHODS, | ||
|
@@ -381,10 +383,13 @@ describe('Shop orders', () => { | |
}); | ||
|
||
it('customer default Addresses are not updated before payment', async () => { | ||
// TODO: will need to be reworked for https://github.com/vendure-ecommerce/vendure/issues/98 | ||
const result = await shopClient.query<GetCustomerAddresses.Query>(GET_ACTIVE_ORDER_ADDRESSES); | ||
const { activeOrder } = await shopClient.query<GetActiveOrder.Query>(GET_ACTIVE_ORDER); | ||
const { customer } = await adminClient.query<GetCustomer.Query, GetCustomer.Variables>( | ||
GET_CUSTOMER, | ||
{ id: activeOrder!.customer!.id }, | ||
); | ||
|
||
expect(result.activeOrder!.customer!.addresses).toEqual([]); | ||
expect(customer!.addresses).toEqual([]); | ||
}); | ||
|
||
it('can transition to ArrangingPayment once Customer has been set', async () => { | ||
|
@@ -965,4 +970,104 @@ describe('Shop orders', () => { | |
expect(activeOrder!.lines[1].productVariant.id).toBe('T_2'); | ||
}); | ||
}); | ||
|
||
describe('security of customer data', () => { | ||
let customers: GetCustomerList.Items[]; | ||
|
||
beforeAll(async () => { | ||
const result = await adminClient.query<GetCustomerList.Query>(GET_CUSTOMER_LIST); | ||
customers = result.customers.items; | ||
}); | ||
|
||
it('cannot setCustomOrder to existing non-guest Customer', async () => { | ||
await shopClient.asAnonymousUser(); | ||
const { addItemToOrder } = await shopClient.query< | ||
AddItemToOrder.Mutation, | ||
AddItemToOrder.Variables | ||
>(ADD_ITEM_TO_ORDER, { | ||
productVariantId: 'T_1', | ||
quantity: 1, | ||
}); | ||
|
||
try { | ||
await shopClient.query<SetCustomerForOrder.Mutation, SetCustomerForOrder.Variables>( | ||
SET_CUSTOMER, | ||
{ | ||
input: { | ||
emailAddress: customers[0].emailAddress, | ||
firstName: 'Evil', | ||
lastName: 'Hacker', | ||
}, | ||
}, | ||
); | ||
fail('Should have thrown'); | ||
} catch (e) { | ||
expect(e.message).toContain( | ||
'Cannot use a registered email address for a guest order. Please log in first', | ||
); | ||
} | ||
const { customer } = await adminClient.query<GetCustomer.Query, GetCustomer.Variables>( | ||
GET_CUSTOMER, | ||
{ | ||
id: customers[0].id, | ||
}, | ||
); | ||
expect(customer!.firstName).not.toBe('Evil'); | ||
expect(customer!.lastName).not.toBe('Hacker'); | ||
}); | ||
|
||
it('guest cannot access Addresses of guest customer', async () => { | ||
await shopClient.asAnonymousUser(); | ||
const { addItemToOrder } = await shopClient.query< | ||
AddItemToOrder.Mutation, | ||
AddItemToOrder.Variables | ||
>(ADD_ITEM_TO_ORDER, { | ||
productVariantId: 'T_1', | ||
quantity: 1, | ||
}); | ||
|
||
await shopClient.query<SetCustomerForOrder.Mutation, SetCustomerForOrder.Variables>( | ||
SET_CUSTOMER, | ||
{ | ||
input: { | ||
emailAddress: '[email protected]', | ||
firstName: 'Evil', | ||
lastName: 'Hacker', | ||
}, | ||
}, | ||
); | ||
|
||
const { activeOrder } = await shopClient.query<GetCustomerAddresses.Query>( | ||
GET_ACTIVE_ORDER_ADDRESSES, | ||
); | ||
|
||
expect(activeOrder!.customer!.addresses).toEqual([]); | ||
}); | ||
|
||
it('guest cannot access Orders of guest customer', async () => { | ||
await shopClient.asAnonymousUser(); | ||
const { addItemToOrder } = await shopClient.query< | ||
AddItemToOrder.Mutation, | ||
AddItemToOrder.Variables | ||
>(ADD_ITEM_TO_ORDER, { | ||
productVariantId: 'T_1', | ||
quantity: 1, | ||
}); | ||
|
||
await shopClient.query<SetCustomerForOrder.Mutation, SetCustomerForOrder.Variables>( | ||
SET_CUSTOMER, | ||
{ | ||
input: { | ||
emailAddress: '[email protected]', | ||
firstName: 'Evil', | ||
lastName: 'Hacker', | ||
}, | ||
}, | ||
); | ||
|
||
const { activeOrder } = await shopClient.query<GetCustomerOrders.Query>(GET_ACTIVE_ORDER_ORDERS); | ||
|
||
expect(activeOrder!.customer!.orders.items).toEqual([]); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters