|
|
@@ -11,29 +11,35 @@ import { testConfig, TEST_SETUP_TIMEOUT_MS } from '../../../e2e-common/test-conf
|
|
|
import { ProtectedFieldsPlugin, transactions } from './fixtures/test-plugins/with-protected-field-resolver';
|
|
|
import {
|
|
|
CreateAdministrator,
|
|
|
+ CreateCustomerGroup,
|
|
|
CreateRole,
|
|
|
ErrorCode,
|
|
|
GetCustomerList,
|
|
|
+ GetTaxRates,
|
|
|
Me,
|
|
|
MutationCreateProductArgs,
|
|
|
MutationLoginArgs,
|
|
|
MutationUpdateProductArgs,
|
|
|
Permission,
|
|
|
+ UpdateTaxRate,
|
|
|
} from './graphql/generated-e2e-admin-types';
|
|
|
import {
|
|
|
ATTEMPT_LOGIN,
|
|
|
CREATE_ADMINISTRATOR,
|
|
|
+ CREATE_CUSTOMER_GROUP,
|
|
|
CREATE_PRODUCT,
|
|
|
CREATE_ROLE,
|
|
|
GET_CUSTOMER_LIST,
|
|
|
GET_PRODUCT_LIST,
|
|
|
+ GET_TAX_RATES_LIST,
|
|
|
ME,
|
|
|
UPDATE_PRODUCT,
|
|
|
+ UPDATE_TAX_RATE,
|
|
|
} from './graphql/shared-definitions';
|
|
|
import { assertThrowsWithMessage } from './utils/assert-throws-with-message';
|
|
|
|
|
|
describe('Authorization & permissions', () => {
|
|
|
- const { server, adminClient } = createTestEnvironment({
|
|
|
+ const { server, adminClient, shopClient } = createTestEnvironment({
|
|
|
...testConfig,
|
|
|
plugins: [ProtectedFieldsPlugin],
|
|
|
});
|
|
|
@@ -42,7 +48,7 @@ describe('Authorization & permissions', () => {
|
|
|
await server.init({
|
|
|
initialData,
|
|
|
productsCsvPath: path.join(__dirname, 'fixtures/e2e-products-minimal.csv'),
|
|
|
- customerCount: 1,
|
|
|
+ customerCount: 5,
|
|
|
});
|
|
|
await adminClient.asSuperAdmin();
|
|
|
}, TEST_SETUP_TIMEOUT_MS);
|
|
|
@@ -239,6 +245,68 @@ describe('Authorization & permissions', () => {
|
|
|
{ id: 'T_2', amount: -50, description: 'debit' },
|
|
|
]);
|
|
|
});
|
|
|
+
|
|
|
+ // https://github.com/vendure-ecommerce/vendure/issues/730
|
|
|
+ it('protects against deep query data leakage', async () => {
|
|
|
+ await adminClient.asSuperAdmin();
|
|
|
+ const { createCustomerGroup } = await adminClient.query<
|
|
|
+ CreateCustomerGroup.Mutation,
|
|
|
+ CreateCustomerGroup.Variables
|
|
|
+ >(CREATE_CUSTOMER_GROUP, {
|
|
|
+ input: {
|
|
|
+ name: 'Test group',
|
|
|
+ customerIds: ['T_1', 'T_2', 'T_3', 'T_4'],
|
|
|
+ },
|
|
|
+ });
|
|
|
+
|
|
|
+ const taxRateName = `Standard Tax ${initialData.defaultZone}`;
|
|
|
+ const { taxRates } = await adminClient.query<GetTaxRates.Query, GetTaxRates.Variables>(
|
|
|
+ GET_TAX_RATES_LIST,
|
|
|
+ {
|
|
|
+ options: {
|
|
|
+ filter: {
|
|
|
+ name: { eq: taxRateName },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ );
|
|
|
+
|
|
|
+ const standardTax = taxRates.items[0];
|
|
|
+ expect(standardTax.name).toBe(taxRateName);
|
|
|
+
|
|
|
+ await adminClient.query<UpdateTaxRate.Mutation, UpdateTaxRate.Variables>(UPDATE_TAX_RATE, {
|
|
|
+ input: {
|
|
|
+ id: standardTax.id,
|
|
|
+ customerGroupId: createCustomerGroup.id,
|
|
|
+ },
|
|
|
+ });
|
|
|
+
|
|
|
+ try {
|
|
|
+ const status = await shopClient.query(
|
|
|
+ gql(`
|
|
|
+ query {
|
|
|
+ product(id: "T_1") {
|
|
|
+ variants {
|
|
|
+ taxRateApplied {
|
|
|
+ customerGroup {
|
|
|
+ customers {
|
|
|
+ items {
|
|
|
+ id
|
|
|
+ emailAddress
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }`),
|
|
|
+ { id: 'T_1' },
|
|
|
+ );
|
|
|
+ fail(`Should have thrown`);
|
|
|
+ } catch (e) {
|
|
|
+ expect(getErrorCode(e)).toBe('FORBIDDEN');
|
|
|
+ }
|
|
|
+ });
|
|
|
});
|
|
|
|
|
|
async function assertRequestAllowed<V>(operation: DocumentNode, variables?: V) {
|