-
Notifications
You must be signed in to change notification settings - Fork 741
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Global API Key (X-Auth-Key) support to Wrangler
- Loading branch information
Showing
6 changed files
with
153 additions
and
56 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,7 +51,7 @@ describe("getUserInfo()", () => { | |
|
||
const userInfo = await getUserInfo(); | ||
expect(userInfo).toEqual({ | ||
authType: "API", | ||
authType: "API Token", | ||
apiToken: "123456789", | ||
email: "[email protected]", | ||
accounts: [ | ||
|
@@ -62,6 +62,67 @@ describe("getUserInfo()", () => { | |
}); | ||
}); | ||
|
||
it("should say it's using a Global API Key when one is set", async () => { | ||
process.env = { | ||
CLOUDFLARE_GLOBAL_API_KEY: "123456789", | ||
CLOUDFLARE_GLOBAL_API_EMAIL: "[email protected]", | ||
}; | ||
setMockResponse("/accounts", () => { | ||
return [ | ||
{ name: "Account One", id: "account-1" }, | ||
{ name: "Account Two", id: "account-2" }, | ||
{ name: "Account Three", id: "account-3" }, | ||
]; | ||
}); | ||
|
||
const userInfo = await getUserInfo(); | ||
expect(userInfo).toEqual({ | ||
authType: "Global API Key", | ||
apiToken: "123456789", | ||
email: "[email protected]", | ||
accounts: [ | ||
{ name: "Account One", id: "account-1" }, | ||
{ name: "Account Two", id: "account-2" }, | ||
{ name: "Account Three", id: "account-3" }, | ||
], | ||
}); | ||
}); | ||
|
||
it("should use a Global API Key in preference to an API key", async () => { | ||
process.env = { | ||
CLOUDFLARE_GLOBAL_API_KEY: "123456789", | ||
CLOUDFLARE_GLOBAL_API_EMAIL: "[email protected]", | ||
CLOUDFLARE_API_TOKEN: "123456789", | ||
}; | ||
setMockResponse("/accounts", () => { | ||
return [ | ||
{ name: "Account One", id: "account-1" }, | ||
{ name: "Account Two", id: "account-2" }, | ||
{ name: "Account Three", id: "account-3" }, | ||
]; | ||
}); | ||
|
||
const userInfo = await getUserInfo(); | ||
expect(userInfo).toEqual({ | ||
authType: "Global API Key", | ||
apiToken: "123456789", | ||
email: "[email protected]", | ||
accounts: [ | ||
{ name: "Account One", id: "account-1" }, | ||
{ name: "Account Two", id: "account-2" }, | ||
{ name: "Account Three", id: "account-3" }, | ||
], | ||
}); | ||
}); | ||
|
||
it("should return undefined only a Global API Key, but not Email, is set", async () => { | ||
process.env = { | ||
CLOUDFLARE_GLOBAL_API_KEY: "123456789", | ||
}; | ||
const userInfo = await getUserInfo(); | ||
expect(userInfo).toEqual(undefined); | ||
}); | ||
|
||
it("should return the user's email and accounts if authenticated via config token", async () => { | ||
writeAuthConfigFile({ oauth_token: "some-oauth-token" }); | ||
|
||
|
@@ -79,7 +140,7 @@ describe("getUserInfo()", () => { | |
const userInfo = await getUserInfo(); | ||
|
||
expect(userInfo).toEqual({ | ||
authType: "OAuth", | ||
authType: "OAuth Token", | ||
apiToken: "some-oauth-token", | ||
email: "[email protected]", | ||
accounts: [ | ||
|
@@ -116,7 +177,7 @@ describe("WhoAmI component", () => { | |
|
||
it("should display the user's email and accounts", async () => { | ||
const user: UserInfo = { | ||
authType: "OAuth", | ||
authType: "OAuth Token", | ||
apiToken: "some-oauth-token", | ||
email: "[email protected]", | ||
accounts: [ | ||
|
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
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