|
|
@@ -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: 'test@test.com',
|
|
|
+ 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: 'test@test.com',
|
|
|
+ firstName: 'Evil',
|
|
|
+ lastName: 'Hacker',
|
|
|
+ },
|
|
|
+ },
|
|
|
+ );
|
|
|
+
|
|
|
+ const { activeOrder } = await shopClient.query<GetCustomerOrders.Query>(GET_ACTIVE_ORDER_ORDERS);
|
|
|
+
|
|
|
+ expect(activeOrder!.customer!.orders.items).toEqual([]);
|
|
|
+ });
|
|
|
+ });
|
|
|
});
|