-
-
Notifications
You must be signed in to change notification settings - Fork 1.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): Allow case-sensitive Administrator identifiers
Fixes #2485
- Loading branch information
1 parent
cb13de4
commit 6527e23
Showing
4 changed files
with
113 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,21 @@ | ||
import { SUPER_ADMIN_USER_IDENTIFIER } from '@vendure/common/lib/shared-constants'; | ||
import { createTestEnvironment } from '@vendure/testing'; | ||
import { createErrorResultGuard, createTestEnvironment, ErrorResultGuard } from '@vendure/testing'; | ||
import { fail } from 'assert'; | ||
import gql from 'graphql-tag'; | ||
import path from 'path'; | ||
import { afterAll, beforeAll, describe, expect, it } from 'vitest'; | ||
|
||
import { initialData } from '../../../e2e-common/e2e-initial-data'; | ||
import { testConfig, TEST_SETUP_TIMEOUT_MS } from '../../../e2e-common/test-config'; | ||
import { TEST_SETUP_TIMEOUT_MS, testConfig } from '../../../e2e-common/test-config'; | ||
|
||
import { ADMINISTRATOR_FRAGMENT } from './graphql/fragments'; | ||
import * as Codegen from './graphql/generated-e2e-admin-types'; | ||
import { AdministratorFragment, DeletionResult } from './graphql/generated-e2e-admin-types'; | ||
import { | ||
AdministratorFragment, | ||
AttemptLoginDocument, | ||
CurrentUser, | ||
DeletionResult, | ||
} from './graphql/generated-e2e-admin-types'; | ||
import { CREATE_ADMINISTRATOR, UPDATE_ADMINISTRATOR } from './graphql/shared-definitions'; | ||
import { assertThrowsWithMessage } from './utils/assert-throws-with-message'; | ||
|
||
|
@@ -235,6 +240,32 @@ describe('Administrator resolver', () => { | |
expect(activeAdministrator?.firstName).toBe('Thomas'); | ||
expect(activeAdministrator?.user.identifier).toBe('[email protected]'); | ||
}); | ||
|
||
it('supports case-sensitive admin identifiers', async () => { | ||
const loginResultGuard: ErrorResultGuard<CurrentUser> = createErrorResultGuard( | ||
input => !!input.identifier, | ||
); | ||
const { createAdministrator } = await adminClient.query< | ||
Codegen.CreateAdministratorMutation, | ||
Codegen.CreateAdministratorMutationVariables | ||
>(CREATE_ADMINISTRATOR, { | ||
input: { | ||
emailAddress: 'NewAdmin', | ||
firstName: 'New', | ||
lastName: 'Admin', | ||
password: 'password', | ||
roleIds: ['1'], | ||
}, | ||
}); | ||
|
||
const { login } = await adminClient.query(AttemptLoginDocument, { | ||
username: 'NewAdmin', | ||
password: 'password', | ||
}); | ||
|
||
loginResultGuard.assertSuccess(login); | ||
expect(login.identifier).toBe('NewAdmin'); | ||
}); | ||
}); | ||
|
||
export const GET_ADMINISTRATORS = gql` | ||
|
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
|
||
import { convertRelationPaths } from './utils'; | ||
import { convertRelationPaths, isEmailAddressLike, normalizeEmailAddress } from './utils'; | ||
|
||
describe('convertRelationPaths()', () => { | ||
it('undefined', () => { | ||
|
@@ -44,3 +44,56 @@ describe('convertRelationPaths()', () => { | |
}); | ||
}); | ||
}); | ||
|
||
describe('normalizeEmailAddress()', () => { | ||
it('should trim whitespace', () => { | ||
expect(normalizeEmailAddress(' [email protected] ')).toBe('[email protected]'); | ||
}); | ||
|
||
it('should lowercase email addresses', async () => { | ||
expect(normalizeEmailAddress('[email protected]')).toBe('[email protected]'); | ||
expect(normalizeEmailAddress('[email protected]')).toBe('[email protected]'); | ||
expect(normalizeEmailAddress('[email protected]')).toBe('[email protected]'); | ||
expect(normalizeEmailAddress('[email protected]')).toBe('[email protected]'); | ||
expect(normalizeEmailAddress('[email protected]')).toBe('[email protected]'); | ||
expect(normalizeEmailAddress('我買@屋企.香港')).toBe('我買@屋企.香港'); | ||
}); | ||
|
||
it('ignores surrounding whitespace', async () => { | ||
expect(normalizeEmailAddress(' [email protected]')).toBe('[email protected]'); | ||
expect(normalizeEmailAddress('[email protected] ')).toBe('[email protected]'); | ||
expect(normalizeEmailAddress(' [email protected] ')).toBe('[email protected]'); | ||
}); | ||
|
||
it('should not lowercase non-email address identifiers', async () => { | ||
expect(normalizeEmailAddress('Test')).toBe('Test'); | ||
expect(normalizeEmailAddress('Ucj30Da2.!3rAA')).toBe('Ucj30Da2.!3rAA'); | ||
}); | ||
}); | ||
|
||
describe('isEmailAddressLike()', () => { | ||
it('returns true for valid email addresses', () => { | ||
expect(isEmailAddressLike('[email protected]')).toBe(true); | ||
expect(isEmailAddressLike('[email protected]')).toBe(true); | ||
expect(isEmailAddressLike('[email protected]')).toBe(true); | ||
expect(isEmailAddressLike('[email protected]')).toBe(true); | ||
expect(isEmailAddressLike('[email protected]')).toBe(true); | ||
expect(isEmailAddressLike('[email protected]')).toBe(true); | ||
expect(isEmailAddressLike('[email protected]')).toBe(true); | ||
expect(isEmailAddressLike('[email protected]')).toBe(true); | ||
expect(isEmailAddressLike('[email protected]')).toBe(true); | ||
}); | ||
|
||
it('ignores surrounding whitespace', () => { | ||
expect(isEmailAddressLike(' [email protected]')).toBe(true); | ||
expect(isEmailAddressLike('[email protected] ')).toBe(true); | ||
expect(isEmailAddressLike(' [email protected] ')).toBe(true); | ||
}); | ||
|
||
it('returns false for invalid email addresses', () => { | ||
expect(isEmailAddressLike('username')).toBe(false); | ||
expect(isEmailAddressLike('823@ee28qje')).toBe(false); | ||
expect(isEmailAddressLike('Abc.example.com')).toBe(false); | ||
expect(isEmailAddressLike('A@b@')).toBe(false); | ||
}); | ||
}); |
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