Repository navigation
improvement(favicons): resolve platform tenants no provider can see, retry timeout-derived icons, no miss flash #9497
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ec7b31c
improvement(favicons): resolve platform tenants no provider can see, …
waleedlatif1 1d15062
improvement(favicons): correct the platform table from vendor docs an…
waleedlatif1 4d7d451
fix(favicons): keep provisional icons provisional through reuse, walk…
waleedlatif1 ebd362e
chore(favicons): import resolver test mocks from their own files
waleedlatif1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| import { parse } from 'tldts' | ||
|
|
||
| /** | ||
| * Platforms whose tenant hosts no icon provider can see — not even at any parent the walk | ||
| * reaches — mapped to the platform's own site, so a tenant still shows the product it is. A | ||
| * platform whose parent already resolves (`salesforce.com`, `databricks.com`, `atlassian.net`) | ||
| * needs no entry. Generic hosting domains (`herokuapp.com`, `azurewebsites.net`, | ||
| * `cloudfront.net`) are deliberately absent: they serve other companies' apps, and the host's | ||
| * logo would misrepresent them. GitLab Pages on Dedicated (`gitlab-dedicated.site`) maps like | ||
| * `gitlab.io`, whose parent already shows GitLab's icon. | ||
| */ | ||
| const PLATFORM_SITES: ReadonlyMap<string, string> = new Map([ | ||
| ['awsapps.com', 'aws.amazon.com'], | ||
| ['azuredatabricks.net', 'databricks.com'], | ||
| ['coupacloud.com', 'coupa.com'], | ||
| ['coupahost.com', 'coupa.com'], | ||
| ['databricks.us', 'databricks.com'], | ||
| ['databricksapps.com', 'databricks.com'], | ||
| ['databricksapps.mil', 'databricks.com'], | ||
| ['databricksapps.us', 'databricks.com'], | ||
|
waleedlatif1 marked this conversation as resolved.
Resolved
|
||
| ['gitlab-dedicated.com', 'gitlab.com'], | ||
| ['gitlab-dedicated.site', 'gitlab.com'], | ||
| ['gitlab-dedicated.systems', 'gitlab.com'], | ||
| ['jamacloud.com', 'jamasoftware.com'], | ||
| ['oktapreview.com', 'okta.com'], | ||
| ['testrail.io', 'testrail.com'], | ||
| ['ultipro.com', 'ukg.com'], | ||
| ]) | ||
|
|
||
| /** | ||
| * Self-hosted tools conventionally served at `<product>.<company domain>` — only on a company's | ||
| * own domain, never on a hosting platform's suffix (`gitlab.azurewebsites.net` is someone's app). | ||
| */ | ||
| const SELF_HOSTED_PRODUCTS: ReadonlyMap<string, string> = new Map([ | ||
| ['confluence', 'atlassian.com'], | ||
| ['gitlab', 'gitlab.com'], | ||
| ['grafana', 'grafana.com'], | ||
| ['jenkins', 'jenkins.io'], | ||
| ['jira', 'atlassian.com'], | ||
| ['testrail', 'testrail.com'], | ||
| ]) | ||
|
|
||
| /** The public site of the platform a host belongs to, matched on whole labels, or `null`. */ | ||
| export function platformSite(hostname: string): string | null { | ||
| const labels = hostname.split('.') | ||
| for (let index = 0; index < labels.length; index++) { | ||
| const site = PLATFORM_SITES.get(labels.slice(index).join('.')) | ||
| if (site) return site | ||
| } | ||
| if (parse(hostname, { allowPrivateDomains: true }).isPrivate) return null | ||
| return SELF_HOSTED_PRODUCTS.get(labels[0]) ?? null | ||
|
waleedlatif1 marked this conversation as resolved.
Resolved
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| import { | ||
| inputValidationMock, | ||
| inputValidationMockFns, | ||
| } from '@sim/testing/mocks/input-validation.mock' | ||
| import { createMockRedis } from '@sim/testing/mocks/redis.mock' | ||
| import { redisConfigMockFns } from '@sim/testing/mocks/redis-config.mock' | ||
| import { beforeEach, describe, expect, it, vi } from 'vitest' | ||
| import { resolveFavicon } from '@/lib/favicon/resolve.server' | ||
|
|
||
| vi.mock('@/lib/core/security/input-validation.server', () => inputValidationMock) | ||
|
|
||
| const PNG = Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0, 0, 0, 0]) | ||
| const DAY = 24 * 60 * 60 | ||
|
|
||
| type Answer = 'icon' | 'none' | 'timeout' | ||
|
|
||
| /** Each host's answer at both providers; any host not listed has no icon. */ | ||
| let answers: Record<string, Answer> = {} | ||
| let stored: Map<string, { value: Buffer; ttl: number }> | ||
|
|
||
| function hostOf(url: string): string { | ||
| const match = url.match(/url=https:\/\/([^&]+)&/) ?? url.match(/\/ip3\/(.+)\.ico$/) | ||
| if (!match) throw new Error(`Unexpected provider URL ${url}`) | ||
| return match[1] | ||
| } | ||
|
|
||
| beforeEach(() => { | ||
| answers = {} | ||
| stored = new Map() | ||
| const redis = createMockRedis() | ||
| redis.getBuffer.mockImplementation(async (key: string) => stored.get(key)?.value ?? null) | ||
| redis.set.mockImplementation( | ||
| async (key: string, value: Buffer | string, _ex: string, ttl: number) => { | ||
| stored.set(key, { value: Buffer.from(value), ttl }) | ||
| return 'OK' | ||
| } | ||
| ) | ||
| redisConfigMockFns.mockGetRedisClient.mockReturnValue(redis) | ||
| inputValidationMockFns.mockSecureFetchWithValidation.mockImplementation(async (url: string) => { | ||
| const answer = answers[hostOf(url)] ?? 'none' | ||
| if (answer === 'timeout') throw new Error('timed out') | ||
| return { | ||
| status: answer === 'icon' ? 200 : 404, | ||
| arrayBuffer: async () => PNG.buffer.slice(PNG.byteOffset, PNG.byteOffset + PNG.byteLength), | ||
| body: { cancel: async () => {} }, | ||
| } | ||
| }) | ||
| }) | ||
|
|
||
| const ttlOf = (host: string) => stored.get(`favicon:v3:${host}`)?.ttl | ||
|
|
||
| describe('resolveFavicon', () => { | ||
| it('keeps a parent icon chosen after a timeout provisional when a child host reuses it', async () => { | ||
| answers = { 'gitlab.acme-internal.io': 'timeout', 'gitlab.com': 'icon' } | ||
| expect((await resolveFavicon('gitlab.acme-internal.io')).kind).toBe('hit') | ||
| expect(ttlOf('gitlab.acme-internal.io')).toBe(DAY) | ||
|
|
||
| expect((await resolveFavicon('docs.gitlab.acme-internal.io')).kind).toBe('hit') | ||
| expect(ttlOf('docs.gitlab.acme-internal.io')).toBe(DAY) | ||
| }) | ||
|
|
||
| it('still reaches the product fallback after its parent was cached as a miss', async () => { | ||
| answers = { 'atlassian.com': 'icon' } | ||
| expect((await resolveFavicon('acme-internal.io')).kind).toBe('miss') | ||
|
|
||
| expect((await resolveFavicon('jira.acme-internal.io')).kind).toBe('hit') | ||
| }) | ||
|
|
||
| it('remembers a definite icon for a month', async () => { | ||
| answers = { 'acme.example.com': 'icon' } | ||
| expect((await resolveFavicon('acme.example.com')).kind).toBe('hit') | ||
| expect(ttlOf('acme.example.com')).toBe(30 * DAY) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.