Uint8Array migration
This commit is contained in:
@@ -6,7 +6,7 @@ import { assert } from 'chai';
|
||||
import * as Attachment from '../../types/Attachment';
|
||||
import * as MIME from '../../types/MIME';
|
||||
import { SignalService } from '../../protobuf';
|
||||
import { stringToArrayBuffer } from '../../util/stringToArrayBuffer';
|
||||
import * as Bytes from '../../Bytes';
|
||||
import * as logger from '../../logging/log';
|
||||
|
||||
describe('Attachment', () => {
|
||||
@@ -38,7 +38,7 @@ describe('Attachment', () => {
|
||||
describe('getFileExtension', () => {
|
||||
it('should return file extension from content type', () => {
|
||||
const input: Attachment.AttachmentType = {
|
||||
data: stringToArrayBuffer('foo'),
|
||||
data: Bytes.fromString('foo'),
|
||||
contentType: MIME.IMAGE_GIF,
|
||||
};
|
||||
assert.strictEqual(Attachment.getFileExtension(input), 'gif');
|
||||
@@ -46,7 +46,7 @@ describe('Attachment', () => {
|
||||
|
||||
it('should return file extension for QuickTime videos', () => {
|
||||
const input: Attachment.AttachmentType = {
|
||||
data: stringToArrayBuffer('foo'),
|
||||
data: Bytes.fromString('foo'),
|
||||
contentType: MIME.VIDEO_QUICKTIME,
|
||||
};
|
||||
assert.strictEqual(Attachment.getFileExtension(input), 'mov');
|
||||
@@ -58,7 +58,7 @@ describe('Attachment', () => {
|
||||
it('should return existing filename if present', () => {
|
||||
const attachment: Attachment.AttachmentType = {
|
||||
fileName: 'funny-cat.mov',
|
||||
data: stringToArrayBuffer('foo'),
|
||||
data: Bytes.fromString('foo'),
|
||||
contentType: MIME.VIDEO_QUICKTIME,
|
||||
};
|
||||
const actual = Attachment.getSuggestedFilename({ attachment });
|
||||
@@ -69,7 +69,7 @@ describe('Attachment', () => {
|
||||
context('for attachment without filename', () => {
|
||||
it('should generate a filename based on timestamp', () => {
|
||||
const attachment: Attachment.AttachmentType = {
|
||||
data: stringToArrayBuffer('foo'),
|
||||
data: Bytes.fromString('foo'),
|
||||
contentType: MIME.VIDEO_QUICKTIME,
|
||||
};
|
||||
const timestamp = new Date(new Date(0).getTimezoneOffset() * 60 * 1000);
|
||||
@@ -84,7 +84,7 @@ describe('Attachment', () => {
|
||||
context('for attachment with index', () => {
|
||||
it('should generate a filename based on timestamp', () => {
|
||||
const attachment: Attachment.AttachmentType = {
|
||||
data: stringToArrayBuffer('foo'),
|
||||
data: Bytes.fromString('foo'),
|
||||
contentType: MIME.VIDEO_QUICKTIME,
|
||||
};
|
||||
const timestamp = new Date(new Date(0).getTimezoneOffset() * 60 * 1000);
|
||||
@@ -103,7 +103,7 @@ describe('Attachment', () => {
|
||||
it('should return true for images', () => {
|
||||
const attachment: Attachment.AttachmentType = {
|
||||
fileName: 'meme.gif',
|
||||
data: stringToArrayBuffer('gif'),
|
||||
data: Bytes.fromString('gif'),
|
||||
contentType: MIME.IMAGE_GIF,
|
||||
};
|
||||
assert.isTrue(Attachment.isVisualMedia(attachment));
|
||||
@@ -112,7 +112,7 @@ describe('Attachment', () => {
|
||||
it('should return true for videos', () => {
|
||||
const attachment: Attachment.AttachmentType = {
|
||||
fileName: 'meme.mp4',
|
||||
data: stringToArrayBuffer('mp4'),
|
||||
data: Bytes.fromString('mp4'),
|
||||
contentType: MIME.VIDEO_MP4,
|
||||
};
|
||||
assert.isTrue(Attachment.isVisualMedia(attachment));
|
||||
@@ -122,7 +122,7 @@ describe('Attachment', () => {
|
||||
const attachment: Attachment.AttachmentType = {
|
||||
fileName: 'Voice Message.aac',
|
||||
flags: SignalService.AttachmentPointer.Flags.VOICE_MESSAGE,
|
||||
data: stringToArrayBuffer('voice message'),
|
||||
data: Bytes.fromString('voice message'),
|
||||
contentType: MIME.AUDIO_AAC,
|
||||
};
|
||||
assert.isFalse(Attachment.isVisualMedia(attachment));
|
||||
@@ -131,7 +131,7 @@ describe('Attachment', () => {
|
||||
it('should return false for other attachments', () => {
|
||||
const attachment: Attachment.AttachmentType = {
|
||||
fileName: 'foo.json',
|
||||
data: stringToArrayBuffer('{"foo": "bar"}'),
|
||||
data: Bytes.fromString('{"foo": "bar"}'),
|
||||
contentType: MIME.APPLICATION_JSON,
|
||||
};
|
||||
assert.isFalse(Attachment.isVisualMedia(attachment));
|
||||
@@ -142,7 +142,7 @@ describe('Attachment', () => {
|
||||
it('should return true for JSON', () => {
|
||||
const attachment: Attachment.AttachmentType = {
|
||||
fileName: 'foo.json',
|
||||
data: stringToArrayBuffer('{"foo": "bar"}'),
|
||||
data: Bytes.fromString('{"foo": "bar"}'),
|
||||
contentType: MIME.APPLICATION_JSON,
|
||||
};
|
||||
assert.isTrue(Attachment.isFile(attachment));
|
||||
@@ -151,7 +151,7 @@ describe('Attachment', () => {
|
||||
it('should return false for images', () => {
|
||||
const attachment: Attachment.AttachmentType = {
|
||||
fileName: 'meme.gif',
|
||||
data: stringToArrayBuffer('gif'),
|
||||
data: Bytes.fromString('gif'),
|
||||
contentType: MIME.IMAGE_GIF,
|
||||
};
|
||||
assert.isFalse(Attachment.isFile(attachment));
|
||||
@@ -160,7 +160,7 @@ describe('Attachment', () => {
|
||||
it('should return false for videos', () => {
|
||||
const attachment: Attachment.AttachmentType = {
|
||||
fileName: 'meme.mp4',
|
||||
data: stringToArrayBuffer('mp4'),
|
||||
data: Bytes.fromString('mp4'),
|
||||
contentType: MIME.VIDEO_MP4,
|
||||
};
|
||||
assert.isFalse(Attachment.isFile(attachment));
|
||||
@@ -170,7 +170,7 @@ describe('Attachment', () => {
|
||||
const attachment: Attachment.AttachmentType = {
|
||||
fileName: 'Voice Message.aac',
|
||||
flags: SignalService.AttachmentPointer.Flags.VOICE_MESSAGE,
|
||||
data: stringToArrayBuffer('voice message'),
|
||||
data: Bytes.fromString('voice message'),
|
||||
contentType: MIME.AUDIO_AAC,
|
||||
};
|
||||
assert.isFalse(Attachment.isFile(attachment));
|
||||
@@ -182,7 +182,7 @@ describe('Attachment', () => {
|
||||
const attachment: Attachment.AttachmentType = {
|
||||
fileName: 'Voice Message.aac',
|
||||
flags: SignalService.AttachmentPointer.Flags.VOICE_MESSAGE,
|
||||
data: stringToArrayBuffer('voice message'),
|
||||
data: Bytes.fromString('voice message'),
|
||||
contentType: MIME.AUDIO_AAC,
|
||||
};
|
||||
assert.isTrue(Attachment.isVoiceMessage(attachment));
|
||||
@@ -190,7 +190,7 @@ describe('Attachment', () => {
|
||||
|
||||
it('should return true for legacy Android voice message attachment', () => {
|
||||
const attachment: Attachment.AttachmentType = {
|
||||
data: stringToArrayBuffer('voice message'),
|
||||
data: Bytes.fromString('voice message'),
|
||||
contentType: MIME.AUDIO_MP3,
|
||||
};
|
||||
assert.isTrue(Attachment.isVoiceMessage(attachment));
|
||||
@@ -199,7 +199,7 @@ describe('Attachment', () => {
|
||||
it('should return false for other attachments', () => {
|
||||
const attachment: Attachment.AttachmentType = {
|
||||
fileName: 'foo.gif',
|
||||
data: stringToArrayBuffer('foo'),
|
||||
data: Bytes.fromString('foo'),
|
||||
contentType: MIME.IMAGE_GIF,
|
||||
};
|
||||
assert.isFalse(Attachment.isVoiceMessage(attachment));
|
||||
@@ -359,7 +359,7 @@ describe('Attachment', () => {
|
||||
it('should write data to disk and store relative path to it', async () => {
|
||||
const input = {
|
||||
contentType: MIME.IMAGE_JPEG,
|
||||
data: stringToArrayBuffer('Above us only sky'),
|
||||
data: Bytes.fromString('Above us only sky'),
|
||||
fileName: 'foo.jpg',
|
||||
size: 1111,
|
||||
};
|
||||
@@ -371,8 +371,8 @@ describe('Attachment', () => {
|
||||
size: 1111,
|
||||
};
|
||||
|
||||
const expectedAttachmentData = stringToArrayBuffer('Above us only sky');
|
||||
const writeNewAttachmentData = async (attachmentData: ArrayBuffer) => {
|
||||
const expectedAttachmentData = Bytes.fromString('Above us only sky');
|
||||
const writeNewAttachmentData = async (attachmentData: Uint8Array) => {
|
||||
assert.deepEqual(attachmentData, expectedAttachmentData);
|
||||
return 'abc/abcdefgh123456789';
|
||||
};
|
||||
@@ -419,7 +419,7 @@ describe('Attachment', () => {
|
||||
Attachment.migrateDataToFileSystem(input, {
|
||||
writeNewAttachmentData,
|
||||
}),
|
||||
'Expected `attachment.data` to be an array buffer; got: number'
|
||||
'Expected `attachment.data` to be a typed array; got: number'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
@@ -6,7 +6,6 @@ import * as sinon from 'sinon';
|
||||
|
||||
import { IMAGE_GIF, IMAGE_PNG } from '../../types/MIME';
|
||||
import { MessageAttributesType } from '../../model-types.d';
|
||||
import { stringToArrayBuffer } from '../../util/stringToArrayBuffer';
|
||||
import {
|
||||
Avatar,
|
||||
Email,
|
||||
@@ -400,7 +399,7 @@ describe('Contact', () => {
|
||||
otherKey: 'otherValue',
|
||||
avatar: {
|
||||
contentType: 'image/png',
|
||||
data: stringToArrayBuffer('It’s easy if you try'),
|
||||
data: Buffer.from('It’s easy if you try'),
|
||||
},
|
||||
} as unknown) as Avatar,
|
||||
},
|
||||
|
@@ -7,7 +7,7 @@ import * as Message from '../../../types/message/initializeAttachmentMetadata';
|
||||
import { IncomingMessage } from '../../../types/Message';
|
||||
import { SignalService } from '../../../protobuf';
|
||||
import * as MIME from '../../../types/MIME';
|
||||
import { stringToArrayBuffer } from '../../../util/stringToArrayBuffer';
|
||||
import * as Bytes from '../../../Bytes';
|
||||
|
||||
describe('Message', () => {
|
||||
describe('initializeAttachmentMetadata', () => {
|
||||
@@ -22,7 +22,7 @@ describe('Message', () => {
|
||||
attachments: [
|
||||
{
|
||||
contentType: MIME.IMAGE_JPEG,
|
||||
data: stringToArrayBuffer('foo'),
|
||||
data: Bytes.fromString('foo'),
|
||||
fileName: 'foo.jpg',
|
||||
size: 1111,
|
||||
},
|
||||
@@ -38,7 +38,7 @@ describe('Message', () => {
|
||||
attachments: [
|
||||
{
|
||||
contentType: MIME.IMAGE_JPEG,
|
||||
data: stringToArrayBuffer('foo'),
|
||||
data: Bytes.fromString('foo'),
|
||||
fileName: 'foo.jpg',
|
||||
size: 1111,
|
||||
},
|
||||
@@ -63,7 +63,7 @@ describe('Message', () => {
|
||||
attachments: [
|
||||
{
|
||||
contentType: MIME.APPLICATION_OCTET_STREAM,
|
||||
data: stringToArrayBuffer('foo'),
|
||||
data: Bytes.fromString('foo'),
|
||||
fileName: 'foo.bin',
|
||||
size: 1111,
|
||||
},
|
||||
@@ -79,7 +79,7 @@ describe('Message', () => {
|
||||
attachments: [
|
||||
{
|
||||
contentType: MIME.APPLICATION_OCTET_STREAM,
|
||||
data: stringToArrayBuffer('foo'),
|
||||
data: Bytes.fromString('foo'),
|
||||
fileName: 'foo.bin',
|
||||
size: 1111,
|
||||
},
|
||||
@@ -105,7 +105,7 @@ describe('Message', () => {
|
||||
{
|
||||
contentType: MIME.AUDIO_AAC,
|
||||
flags: SignalService.AttachmentPointer.Flags.VOICE_MESSAGE,
|
||||
data: stringToArrayBuffer('foo'),
|
||||
data: Bytes.fromString('foo'),
|
||||
fileName: 'Voice Message.aac',
|
||||
size: 1111,
|
||||
},
|
||||
@@ -122,7 +122,7 @@ describe('Message', () => {
|
||||
{
|
||||
contentType: MIME.AUDIO_AAC,
|
||||
flags: SignalService.AttachmentPointer.Flags.VOICE_MESSAGE,
|
||||
data: stringToArrayBuffer('foo'),
|
||||
data: Bytes.fromString('foo'),
|
||||
fileName: 'Voice Message.aac',
|
||||
size: 1111,
|
||||
},
|
||||
@@ -147,7 +147,7 @@ describe('Message', () => {
|
||||
attachments: [
|
||||
{
|
||||
contentType: MIME.LONG_MESSAGE,
|
||||
data: stringToArrayBuffer('foo'),
|
||||
data: Bytes.fromString('foo'),
|
||||
fileName: 'message.txt',
|
||||
size: 1111,
|
||||
},
|
||||
@@ -163,7 +163,7 @@ describe('Message', () => {
|
||||
attachments: [
|
||||
{
|
||||
contentType: MIME.LONG_MESSAGE,
|
||||
data: stringToArrayBuffer('foo'),
|
||||
data: Bytes.fromString('foo'),
|
||||
fileName: 'message.txt',
|
||||
size: 1111,
|
||||
},
|
||||
|
@@ -4,8 +4,6 @@
|
||||
import { assert } from 'chai';
|
||||
import { size } from '../../util/iterables';
|
||||
|
||||
import { typedArrayToArrayBuffer } from '../../Crypto';
|
||||
|
||||
import { getProvisioningUrl } from '../../util/getProvisioningUrl';
|
||||
|
||||
// It'd be nice to run these tests in the renderer, too, but [Chromium's `URL` doesn't
|
||||
@@ -17,7 +15,7 @@ describe('getProvisioningUrl', () => {
|
||||
const uuid = 'a08bf1fd-1799-427f-a551-70af747e3956';
|
||||
const publicKey = new Uint8Array([9, 8, 7, 6, 5, 4, 3]);
|
||||
|
||||
const result = getProvisioningUrl(uuid, typedArrayToArrayBuffer(publicKey));
|
||||
const result = getProvisioningUrl(uuid, publicKey);
|
||||
const resultUrl = new URL(result);
|
||||
|
||||
assert.strictEqual(resultUrl.protocol, 'sgnl:');
|
||||
|
@@ -13,8 +13,6 @@ import {
|
||||
IMAGE_WEBP,
|
||||
} from '../../types/MIME';
|
||||
|
||||
import { typedArrayToArrayBuffer } from '../../Crypto';
|
||||
|
||||
import { sniffImageMimeType } from '../../util/sniffImageMimeType';
|
||||
|
||||
describe('sniffImageMimeType', () => {
|
||||
@@ -89,11 +87,4 @@ describe('sniffImageMimeType', () => {
|
||||
IMAGE_JPEG
|
||||
);
|
||||
});
|
||||
|
||||
it('handles ArrayBuffers', async () => {
|
||||
const arrayBuffer = typedArrayToArrayBuffer(
|
||||
await fixture('kitten-1-64-64.jpg')
|
||||
);
|
||||
assert.strictEqual(sniffImageMimeType(arrayBuffer), IMAGE_JPEG);
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user