From e64854eb14701cacf1c4b505792da05e5d15003f Mon Sep 17 00:00:00 2001 From: FoxxMD Date: Mon, 14 Jul 2025 13:43:22 +0000 Subject: [PATCH] fix(plex): Strict comparison of libnrary names #326 * Fixes libraries containing partial allow/disallow names from being able to pass filter * Fix not checking valid library types --- src/backend/sources/PlexApiSource.ts | 12 ++++++------ src/backend/tests/plex/plex.test.ts | 9 +++++++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/backend/sources/PlexApiSource.ts b/src/backend/sources/PlexApiSource.ts index 570416c5..6f0fc4e0 100644 --- a/src/backend/sources/PlexApiSource.ts +++ b/src/backend/sources/PlexApiSource.ts @@ -232,22 +232,22 @@ export default class PlexApiSource extends MemoryPositionalSource { if(state.play !== undefined) { const allowedLibraries = this.getAllowedLibraries(); - if(allowedLibraries.length > 0 && !allowedLibraries.some(x => state.play.meta.library.toLocaleLowerCase().includes(x.name.toLocaleLowerCase()))) { + if(allowedLibraries.length > 0 && !allowedLibraries.some(x => state.play.meta.library.toLocaleLowerCase() === x.name.toLocaleLowerCase())) { return `media not included in librariesAllow`; } if(allowedLibraries.length === 0) { const blockedLibraries = this.getBlockedLibraries(); if(blockedLibraries.length > 0) { - const blockedLibrary = blockedLibraries.find(x => state.play.meta.library.toLocaleLowerCase().includes(x.name.toLocaleLowerCase())); + const blockedLibrary = blockedLibraries.find(x => state.play.meta.library.toLocaleLowerCase() === x.name.toLocaleLowerCase()); if(blockedLibrary !== undefined) { return `media included in librariesBlock '${blockedLibrary.name}'`; } } - - if(!this.getValidLibraries().some(x => state.play.meta.library === x.name)) { - return `media not included in a valid library`; - } + } + + if(!this.getValidLibraries().some(x => state.play.meta.library === x.name)) { + return `media not included in a valid library`; } } diff --git a/src/backend/tests/plex/plex.test.ts b/src/backend/tests/plex/plex.test.ts index 4d814f23..c26e70ce 100644 --- a/src/backend/tests/plex/plex.test.ts +++ b/src/backend/tests/plex/plex.test.ts @@ -134,18 +134,27 @@ describe("Plex API Source", function() { it('Should allow activity based on libraries allow', async function () { const s = await createSource({...defaultCreds, librariesAllow: ['music']}); + s.libraries.push({name: 'SomeOtherLibrary', collectionType: 'artist', uuid: '43543'}); + s.libraries.push({name: 'Study Music', collectionType: 'artist', uuid: '435437'}); + s.libraries.push({name: 'Music', collectionType: 'artist', uuid: '4354378'}); expect(s.isActivityValid(validPlayerState, validSession)).to.be.true; expect(s.isActivityValid(playWithMeta({library: 'SomeOtherLibrary'}), nowPlayingSession({librarySectionTitle: 'SomeOtherLibrary'}))).to.not.be.true; + expect(s.isActivityValid(playWithMeta({library: 'Study Music'}), nowPlayingSession({librarySectionTitle: 'Study Music'}))).to.not.be.true; + expect(s.isActivityValid(playWithMeta({library: 'Music'}), nowPlayingSession({librarySectionTitle: 'Music'}))).to.be.true; await s.destroy(); }); it('Should disallow activity based on libraries block', async function () { const s = await createSource({...defaultCreds, librariesBlock: ['music']}); s.libraries.push({name: 'CoolVideos', collectionType: 'artist', uuid: '43543'}); + s.libraries.push({name: 'Study Music', collectionType: 'artist', uuid: '435437'}); + s.libraries.push({name: 'Music', collectionType: 'artist', uuid: '4354378'}); expect(s.isActivityValid(validPlayerState, validSession)).to.not.be.true; expect(s.isActivityValid(playWithMeta({library: 'CoolVideos'}), nowPlayingSession({librarySectionTitle: 'CoolVideos'}))).to.be.true; + expect(s.isActivityValid(playWithMeta({library: 'Study Music'}), nowPlayingSession({librarySectionTitle: 'Study Music'}))).to.be.true; + expect(s.isActivityValid(playWithMeta({library: 'Music'}), nowPlayingSession({librarySectionTitle: 'Music'}))).to.not.be.true; await s.destroy(); }); -- 2.51.2