Skip to content

Commit

Permalink
Remove unused getSecurityHeaders function
Browse files Browse the repository at this point in the history
  • Loading branch information
3flex committed Nov 10, 2024
1 parent ace5bde commit 7c2f3aa
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 74 deletions.
41 changes: 0 additions & 41 deletions src/components/__tests__/jellyfinApi.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { describe, beforeAll, beforeEach, test, expect } from 'vitest';
import { JellyfinApi } from '../jellyfinApi';
import { version } from '../../../package.json';

const setupMockCastSenders = (): void => {
const getSenders = (): any[] => [{ id: 'thisIsSenderId' }]; // eslint-disable-line @typescript-eslint/no-explicit-any
Expand Down Expand Up @@ -141,43 +140,3 @@ describe('creating image urls', () => {
expect(result).toEqual(correct);
});
});

describe('getting security headers', () => {
beforeAll(() => {
setupMockCastSenders();
});

test('should return correct auth header with all server details set', () => {
JellyfinApi.setServerInfo(
'thisIsUserId',
'thisIsAccessToken',
'thisIsServerAddress',
'thisIsReceiverName'
);

// @ts-expect-error Since the method is private.
const result = JellyfinApi.getSecurityHeaders();
const correctAuth = `MediaBrowser Client="Chromecast", Version="${version}", Token="thisIsAccessToken", DeviceId="${btoa(
'thisIsReceiverName'
)}", Device="thisIsReceiverName"`;

expect(result).toHaveProperty('Authorization');
expect(result.Authorization).toMatch(correctAuth);
});

test('should return correct auth header with minimal server details set', () => {
JellyfinApi.setServerInfo(
undefined,
'thisIsAccessToken',
'thisIsServerAddress'
);

// @ts-expect-error Since the method is private.
const result = JellyfinApi.getSecurityHeaders();
const correct = {
Authorization: `MediaBrowser Client="Chromecast", Version="${version}", Token="thisIsAccessToken", DeviceId="thisIsSenderId", Device="Google%20Cast"`
};

expect(result).toMatchObject(correct);
});
});
33 changes: 0 additions & 33 deletions src/components/jellyfinApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,39 +108,6 @@ export abstract class JellyfinApi {
}
}

// create the necessary headers for authentication
private static getSecurityHeaders(): { Authorization?: string } {
const parameters: Record<string, string> = {
Client: 'Chromecast',
Version: packageVersion
};

if (this.accessToken) {
parameters.Token = this.accessToken;
}

if (this.deviceId) {
parameters.DeviceId = this.deviceId;
}

if (this.deviceName) {
parameters.Device = this.deviceName;
}

let header = 'MediaBrowser';

for (const [key, value] of Object.entries(parameters)) {
header += ` ${key}="${encodeURIComponent(value)}", `;
}

// Remove last comma
header = header.substring(0, header.length - 2);

return {
Authorization: header
};
}

// Create a basic url.
// Cannot start with /.
public static createUrl(path: string): string {
Expand Down

0 comments on commit 7c2f3aa

Please sign in to comment.