mirror of
https://github.com/SableClient/Sable.git
synced 2026-11-24 02:51:17 -08:00
fix: satisfy media retry checks
This commit is contained in:
5 files changed
+32
-23
No files matched your search
@@ -1867,8 +1867,14 @@ mod tests {
|
||||
fn retry_fragment_gives_a_distinct_cache_identity() {
|
||||
let base = "https://matrix.example.org/_matrix/client/v1/media/download/matrix.org/abc123";
|
||||
let original = cache_key("@a:example.org", base);
|
||||
assert_ne!(original, cache_key("@a:example.org", &format!("{base}#retry=1")));
|
||||
assert_ne!(original, cache_key("@a:example.org", &format!("{base}#retry=2")));
|
||||
assert_ne!(
|
||||
original,
|
||||
cache_key("@a:example.org", &format!("{base}#retry=1"))
|
||||
);
|
||||
assert_ne!(
|
||||
original,
|
||||
cache_key("@a:example.org", &format!("{base}#retry=2"))
|
||||
);
|
||||
assert_eq!(
|
||||
cache_key("@a:example.org", &format!("{base}#retry=1")),
|
||||
cache_key("@a:example.org", &format!("{base}#retry=1"))
|
||||
|
||||
@@ -21,8 +21,8 @@ const SABLE_MEDIA_URL =
|
||||
vi.mock('$utils/matrix', () => ({
|
||||
mxcUrlToHttp: () => SABLE_MEDIA_URL,
|
||||
rewriteAuthenticatedMediaUrl: (url: string | null) => url,
|
||||
downloadEncryptedMedia: vi.fn(),
|
||||
decryptFile: vi.fn(),
|
||||
downloadEncryptedMedia: vi.fn<() => Promise<ArrayBuffer>>(),
|
||||
decryptFile: vi.fn<() => Promise<ArrayBuffer>>(),
|
||||
}));
|
||||
|
||||
vi.mock('$hooks/useMatrixClient', () => ({
|
||||
|
||||
@@ -25,9 +25,9 @@ const SABLE_MEDIA_URL =
|
||||
vi.mock('$utils/matrix', () => ({
|
||||
mxcUrlToHttp: () => SABLE_MEDIA_URL,
|
||||
rewriteAuthenticatedMediaUrl: (url: string | null) => url,
|
||||
downloadMedia: vi.fn(),
|
||||
downloadEncryptedMedia: vi.fn(),
|
||||
decryptFile: vi.fn(),
|
||||
downloadMedia: vi.fn<() => Promise<ArrayBuffer>>(),
|
||||
downloadEncryptedMedia: vi.fn<() => Promise<ArrayBuffer>>(),
|
||||
decryptFile: vi.fn<() => Promise<ArrayBuffer>>(),
|
||||
}));
|
||||
vi.mock('$utils/swMediaAuth', () => ({
|
||||
probeSWMediaAuthSupport: async () => true,
|
||||
@@ -44,7 +44,11 @@ describe('VideoContent', () => {
|
||||
info={{ w: 640, h: 360, duration: 1000 }}
|
||||
renderVideo={(props) => {
|
||||
srcs.push(props.src);
|
||||
return <video data-testid="video" src={props.src} onError={props.onError} />;
|
||||
return (
|
||||
<video data-testid="video" src={props.src} onError={props.onError}>
|
||||
<track kind="captions" />
|
||||
</video>
|
||||
);
|
||||
}}
|
||||
/>
|
||||
);
|
||||
@@ -58,15 +62,15 @@ describe('VideoContent', () => {
|
||||
fireEvent.error(video);
|
||||
fireEvent.click(await screen.findByRole('button', { name: 'Retry' }));
|
||||
|
||||
await waitFor(() => {
|
||||
const retriedSrc = srcs[srcs.length - 1] ?? '';
|
||||
expect(retriedSrc).not.toBe(initialSrc);
|
||||
// The decoded scheme path is the `target` Rust feeds into cache_key.
|
||||
const schemePath = retriedSrc.replace(/^sable-media:\/\/localhost\//, '').split('?')[0]!;
|
||||
expect(decodeURIComponent(schemePath)).toMatch(
|
||||
/^https:\/\/hs\.example\/_matrix\/client\/v1\/media\/download\/example\.org\/vid123#__sable_media_retry=\d+$/
|
||||
);
|
||||
expect(retriedSrc).toContain('__sable_media_cache=3');
|
||||
});
|
||||
await waitFor(() => {
|
||||
const retriedSrc = srcs[srcs.length - 1] ?? '';
|
||||
expect(retriedSrc).not.toBe(initialSrc);
|
||||
// The decoded scheme path is the `target` Rust feeds into cache_key.
|
||||
const schemePath = retriedSrc.replace(/^sable-media:\/\/localhost\//, '').split('?')[0]!;
|
||||
expect(decodeURIComponent(schemePath)).toMatch(
|
||||
/^https:\/\/hs\.example\/_matrix\/client\/v1\/media\/download\/example\.org\/vid123#__sable_media_retry=\d+$/
|
||||
);
|
||||
expect(retriedSrc).toContain('__sable_media_cache=3');
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -140,8 +140,7 @@ describe('rewriteAuthenticatedMediaUrl', () => {
|
||||
});
|
||||
|
||||
describe('addTauriMediaRetryRevision', () => {
|
||||
const INNER =
|
||||
'https://matrix.example.com/_matrix/client/v1/media/download/example.com/abc123';
|
||||
const INNER = 'https://matrix.example.com/_matrix/client/v1/media/download/example.com/abc123';
|
||||
const REWRITTEN = `sable-media://${INNER}?__sable_media_cache=3&__sable_media_session=session_abc`;
|
||||
|
||||
afterEach(() => {
|
||||
|
||||
@@ -2,9 +2,9 @@ import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
|
||||
vi.mock('@tauri-apps/api/core', () => ({ isTauri: (): boolean => true }));
|
||||
|
||||
const updateTauriMediaSession = vi.fn(
|
||||
(_baseUrl?: string, _accessToken?: string, _userId?: string) => Promise.resolve()
|
||||
);
|
||||
const updateTauriMediaSession = vi.fn<
|
||||
(baseUrl?: string, accessToken?: string, userId?: string) => Promise<void>
|
||||
>(() => Promise.resolve());
|
||||
vi.mock('./app/utils/tauriMediaAuth', () => ({
|
||||
updateTauriMediaSession: (baseUrl?: string, accessToken?: string, userId?: string) =>
|
||||
updateTauriMediaSession(baseUrl, accessToken, userId),
|
||||
|
||||
Reference in new issue
Block a user