-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add Grafana Cloud to integration connect #85
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
3 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| import { describe, it } from 'node:test'; | ||
| import assert from 'node:assert/strict'; | ||
| import { normalizeGrafanaStackUrl } from '../src/commands/integration/connect'; | ||
|
|
||
| describe('normalizeGrafanaStackUrl', () => { | ||
| it('keeps a clean stack URL as-is', () => { | ||
| assert.equal(normalizeGrafanaStackUrl('https://acme.grafana.net'), 'https://acme.grafana.net'); | ||
| }); | ||
|
|
||
| it('adds https:// to a bare host', () => { | ||
| assert.equal(normalizeGrafanaStackUrl('acme.grafana.net'), 'https://acme.grafana.net'); | ||
| }); | ||
|
|
||
| it('strips trailing slashes and deep paths', () => { | ||
| assert.equal(normalizeGrafanaStackUrl('https://acme.grafana.net/'), 'https://acme.grafana.net'); | ||
| assert.equal( | ||
| normalizeGrafanaStackUrl('https://acme.grafana.net/d/abc123/my-dashboard?orgId=1'), | ||
| 'https://acme.grafana.net' | ||
| ); | ||
| }); | ||
|
|
||
| it('trims surrounding whitespace', () => { | ||
| assert.equal(normalizeGrafanaStackUrl(' acme.grafana.net \n'), 'https://acme.grafana.net'); | ||
| }); | ||
|
|
||
| it('keeps an explicit port for self-hosted Grafana', () => { | ||
| assert.equal(normalizeGrafanaStackUrl('https://grafana.example.com:3000/'), 'https://grafana.example.com:3000'); | ||
| }); | ||
|
|
||
| it('rejects http URLs', () => { | ||
| assert.equal(normalizeGrafanaStackUrl('http://acme.grafana.net'), null); | ||
| }); | ||
|
|
||
| it('rejects empty and whitespace-only values', () => { | ||
| assert.equal(normalizeGrafanaStackUrl(''), null); | ||
| assert.equal(normalizeGrafanaStackUrl(' '), null); | ||
| }); | ||
|
|
||
| it('rejects hosts without a dot', () => { | ||
| assert.equal(normalizeGrafanaStackUrl('localhost'), null); | ||
| assert.equal(normalizeGrafanaStackUrl('https://grafana'), null); | ||
| }); | ||
|
|
||
| it('rejects values that do not parse as a URL', () => { | ||
| assert.equal(normalizeGrafanaStackUrl('https://'), null); | ||
| assert.equal(normalizeGrafanaStackUrl('not a url'), null); | ||
| }); | ||
|
|
||
| it('rejects loopback and 0/8 hosts, including canonicalized IPv4 forms', () => { | ||
| assert.equal(normalizeGrafanaStackUrl('https://127.0.0.1'), null); | ||
| assert.equal(normalizeGrafanaStackUrl('https://127.0.0.1:3000'), null); | ||
| assert.equal(normalizeGrafanaStackUrl('https://0.0.0.0'), null); | ||
| // The WHATWG URL parser canonicalizes hex / octal / integer forms to dotted-quad. | ||
| assert.equal(normalizeGrafanaStackUrl('https://0x7f000001'), null); | ||
| assert.equal(normalizeGrafanaStackUrl('https://2130706433'), null); | ||
|
claude[bot] marked this conversation as resolved.
|
||
| assert.equal(normalizeGrafanaStackUrl('https://0177.0.0.1'), null); | ||
| assert.equal(normalizeGrafanaStackUrl('https://017700000001'), null); | ||
| }); | ||
|
|
||
| it('rejects RFC1918 private ranges', () => { | ||
| assert.equal(normalizeGrafanaStackUrl('https://10.0.0.5'), null); | ||
| assert.equal(normalizeGrafanaStackUrl('https://172.16.0.1'), null); | ||
| assert.equal(normalizeGrafanaStackUrl('https://172.31.255.255'), null); | ||
| assert.equal(normalizeGrafanaStackUrl('https://192.168.1.1'), null); | ||
| }); | ||
|
|
||
| it('rejects link-local hosts, including the cloud metadata endpoint', () => { | ||
| assert.equal(normalizeGrafanaStackUrl('https://169.254.169.254'), null); | ||
| assert.equal(normalizeGrafanaStackUrl('https://169.254.0.1'), null); | ||
| }); | ||
|
|
||
| it('rejects localhost names and bracketed IPv6 literals', () => { | ||
| assert.equal(normalizeGrafanaStackUrl('https://grafana.localhost'), null); | ||
| assert.equal(normalizeGrafanaStackUrl('https://[::1]'), null); | ||
| assert.equal(normalizeGrafanaStackUrl('https://[::ffff:127.0.0.1]'), null); | ||
| }); | ||
|
|
||
| it('accepts public IPs that only look like private-range boundaries', () => { | ||
| assert.equal(normalizeGrafanaStackUrl('https://172.15.0.1'), 'https://172.15.0.1'); | ||
| assert.equal(normalizeGrafanaStackUrl('https://172.32.0.1'), 'https://172.32.0.1'); | ||
| assert.equal(normalizeGrafanaStackUrl('https://192.169.0.1'), 'https://192.169.0.1'); | ||
| assert.equal(normalizeGrafanaStackUrl('https://169.253.0.1'), 'https://169.253.0.1'); | ||
| }); | ||
| }); | ||
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.