mirror of
https://github.com/strapi/strapi.git
synced 2025-11-03 03:17:11 +00:00
Fix test, add missing await clause, add web crypto api for FE user hash
This commit is contained in:
parent
16c0e79557
commit
b9db4a0bea
@ -93,7 +93,7 @@ function App() {
|
||||
setTelemetryProperties(properties);
|
||||
|
||||
try {
|
||||
fetch('https://analytics.strapi.io/api/v2/track', {
|
||||
await fetch('https://analytics.strapi.io/api/v2/track', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
// This event is anonymous
|
||||
|
||||
@ -1,12 +1,22 @@
|
||||
const hash = require('hash.js');
|
||||
function bufferToHex(buffer) {
|
||||
return [...new Uint8Array(buffer)].map((b) => b.toString(16).padStart(2, '0')).join('');
|
||||
}
|
||||
|
||||
const hashAdminUserEmail = (payload) => {
|
||||
async function digestMessage(message) {
|
||||
const msgUint8 = new TextEncoder().encode(message);
|
||||
const hashBuffer = await crypto.subtle.digest('SHA-256', msgUint8);
|
||||
|
||||
return bufferToHex(hashBuffer);
|
||||
}
|
||||
|
||||
const hashAdminUserEmail = async (payload) => {
|
||||
try {
|
||||
const adminUserEmailHash = hash.sha256().update(payload.email).digest('hex');
|
||||
|
||||
return adminUserEmailHash;
|
||||
return await digestMessage(payload.email);
|
||||
} catch (error) {
|
||||
return '';
|
||||
// not a secure context
|
||||
const hash = import('hash.js');
|
||||
|
||||
return hash.sha256().update(payload.email).digest('hex');
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -25,6 +25,7 @@ function setup(props) {
|
||||
telemetryProperties: {
|
||||
nestedProperty: true,
|
||||
},
|
||||
deviceId: 'someTestDeviceId',
|
||||
...props,
|
||||
}}
|
||||
>
|
||||
@ -45,21 +46,33 @@ describe('useTracking', () => {
|
||||
test('Call trackUsage() with all attributes', async () => {
|
||||
useAppInfos.mockReturnValue({
|
||||
currentEnvironment: 'testing',
|
||||
adminUserId: 'someTestUserId',
|
||||
});
|
||||
|
||||
const { result } = await setup();
|
||||
|
||||
result.current.trackUsage('event', { trackingProperty: true });
|
||||
|
||||
expect(axios.post).toBeCalledWith(expect.any(String), {
|
||||
event: 'event',
|
||||
uuid: 1,
|
||||
properties: expect.objectContaining({
|
||||
environment: 'testing',
|
||||
nestedProperty: true,
|
||||
trackingProperty: true,
|
||||
}),
|
||||
});
|
||||
expect(axios.post).toBeCalledWith(
|
||||
expect.any(String),
|
||||
{
|
||||
adminUserId: 'someTestUserId',
|
||||
deviceId: 'someTestDeviceId',
|
||||
event: 'event',
|
||||
eventProperties: {
|
||||
trackingProperty: true,
|
||||
},
|
||||
groupProperties: {
|
||||
nestedProperty: true,
|
||||
projectId: 1,
|
||||
projectType: 'Community',
|
||||
},
|
||||
userProperties: {},
|
||||
},
|
||||
{
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
test('Do not track if it has been disabled', async () => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user