-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
315 additions
and
242 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
@@ -1,12 +1,13 @@ | ||
{ | ||
"editor.formatOnSave": false, | ||
"editor.codeActionsOnSave": { | ||
"quickfix.rome": true | ||
"quickfix.biome": "explicit", | ||
"source.organizeImports.biome": true | ||
}, | ||
"[javascript]": { | ||
"editor.defaultFormatter": "rome.rome", | ||
"editor.defaultFormatter": "biomejs.biome", | ||
}, | ||
"[typescript]": { | ||
"editor.defaultFormatter": "rome.rome", | ||
"editor.defaultFormatter": "biomejs.biome", | ||
} | ||
} | ||
} |
This file contains 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 |
---|---|---|
@@ -1,40 +1,102 @@ | ||
import { describe, it, expect } from 'vitest'; | ||
import 'cross-fetch/polyfill'; | ||
import { createSignedFetcher } from '../dist/index'; | ||
|
||
describe('IAM', () => { | ||
describe('GET', () => { | ||
it('should get current user', async () => { | ||
const url = 'https://iam.amazonaws.com/?Action=GetUser&Version=2010-05-08'; | ||
|
||
const fetch = createSignedFetcher({ service: 'iam', region: 'us-east-1' }); | ||
const response = await fetch(url, { | ||
method: 'GET' | ||
}); | ||
|
||
expect(response.status).toBe(200); | ||
|
||
const data = await response.text(); | ||
expect(data).toContain('<GetUserResult>'); | ||
}) | ||
}) | ||
|
||
describe('POST', () => { | ||
it('should get current user', async () => { | ||
const url = 'https://iam.amazonaws.com/'; | ||
const body = 'Action=GetUser&Version=2010-05-08' | ||
|
||
const fetch = createSignedFetcher({ service: 'iam', region: 'us-east-1' }); | ||
const response = await fetch(url, { | ||
method: 'POST', | ||
body, | ||
headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8' } | ||
}); | ||
|
||
expect(response.status).toBe(200); | ||
|
||
const data = await response.text(); | ||
expect(data).toContain('<GetUserResult>'); | ||
}) | ||
}) | ||
}) | ||
import "cross-fetch/polyfill"; | ||
import { describe, expect, it } from "vitest"; | ||
import { createSignedFetcher } from "../dist/index"; | ||
|
||
describe("IAM", () => { | ||
it("should handle GET", async () => { | ||
const url = "https://iam.amazonaws.com/?Action=GetUser&Version=2010-05-08"; | ||
|
||
const fetch = createSignedFetcher({ service: "iam", region: "us-east-1" }); | ||
const response = await fetch(url, { | ||
method: "GET", | ||
}); | ||
|
||
expect(response.status).toBe(200); | ||
|
||
const data = await response.text(); | ||
expect(data).toContain("<GetUserResult>"); | ||
}); | ||
|
||
it("should handle POST", async () => { | ||
const url = "https://iam.amazonaws.com/"; | ||
const body = "Action=GetUser&Version=2010-05-08"; | ||
|
||
const fetch = createSignedFetcher({ service: "iam", region: "us-east-1" }); | ||
const response = await fetch(url, { | ||
method: "POST", | ||
body, | ||
headers: { | ||
"Content-Type": "application/x-www-form-urlencoded; charset=utf-8", | ||
}, | ||
}); | ||
|
||
expect(response.status).toBe(200); | ||
|
||
const data = await response.text(); | ||
expect(data).toContain("<GetUserResult>"); | ||
}); | ||
|
||
it("should handle additional headers", async () => { | ||
const url = "https://iam.amazonaws.com/?Action=GetUser&Version=2010-05-08"; | ||
|
||
const headers = { | ||
"x-amz-test-header": "test-value", | ||
"x-api-key": "test-api-key", | ||
}; | ||
|
||
const fetch = createSignedFetcher({ | ||
service: "iam", | ||
region: "us-east-1", | ||
}); | ||
|
||
const response = await fetch(url, { | ||
method: "GET", | ||
headers, | ||
}); | ||
|
||
expect(response.status).toBe(200); | ||
|
||
const data = await response.text(); | ||
expect(data).toContain("<GetUserResult>"); | ||
}); | ||
|
||
it("should handle url fragments", async () => { | ||
const url = | ||
"https://iam.amazonaws.com/?Action=GetUser&Version=2010-05-08#test-fragment"; | ||
|
||
const fetch = createSignedFetcher({ | ||
service: "iam", | ||
region: "us-east-1", | ||
}); | ||
|
||
const response = await fetch(url, { | ||
method: "GET", | ||
}); | ||
|
||
expect(response.status).toBe(200); | ||
|
||
const data = await response.text(); | ||
expect(data).toContain("<GetUserResult>"); | ||
}); | ||
|
||
it("should abort request", async () => { | ||
const url = "https://iam.amazonaws.com/?Action=GetUser&Version=2010-05-08"; | ||
|
||
const controller = new AbortController(); | ||
const signal = controller.signal; | ||
|
||
const fetch = createSignedFetcher({ | ||
service: "iam", | ||
region: "us-east-1", | ||
}); | ||
|
||
const response = fetch(url, { | ||
method: "GET", | ||
signal, | ||
}); | ||
|
||
controller.abort(); | ||
|
||
await expect(response).rejects.toThrow("This operation was aborted"); | ||
}); | ||
}); |
This file contains 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,18 @@ | ||
{ | ||
"$schema": "https://biomejs.dev/schemas/1.5.1/schema.json", | ||
"organizeImports": { | ||
"enabled": true | ||
}, | ||
"linter": { | ||
"enabled": true, | ||
"rules": { | ||
"recommended": true, | ||
"suspicious": { | ||
"noExplicitAny": "off" | ||
}, | ||
"complexity": { | ||
"useLiteralKeys": "off" | ||
} | ||
} | ||
} | ||
} |
This file contains 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.