-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[cadl-ranch-*] Backport the server testing changes from typespec repo…
…sitory to cadl-ranch repository (#741) * Initial Commit * Format and Changeset addition
- Loading branch information
1 parent
23279d1
commit 352934c
Showing
85 changed files
with
7,406 additions
and
3,291 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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"@azure-tools/cadl-ranch-specs": patch | ||
"@azure-tools/cadl-ranch-api": patch | ||
"@azure-tools/cadl-ranch": patch | ||
--- | ||
|
||
Backport the changes from typespec repository to migrate the scenarios to new model |
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
51 changes: 41 additions & 10 deletions
51
packages/cadl-ranch-specs/http/authentication/api-key/mockapi.ts
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,17 +1,48 @@ | ||
import { MockRequest } from "@azure-tools/cadl-ranch-api"; | ||
import { json, MockRequest, passOnSuccess } from "@azure-tools/cadl-ranch-api"; | ||
import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api"; | ||
import { getValidAndInvalidScenarios } from "../commonapi.js"; | ||
|
||
export const Scenarios: Record<string, ScenarioMockApi> = {}; | ||
|
||
const validAndInvalidScenarios = getValidAndInvalidScenarios( | ||
"api-key", | ||
"invalid-api-key", | ||
function addOptionalParamOldApiVersionNewClientValidate(req: MockRequest): void { | ||
Scenarios.Authentication_ApiKey_valid = passOnSuccess({ | ||
uri: `/authentication/api-key/valid`, | ||
method: `get`, | ||
request: { | ||
headers: { | ||
"x-ms-api-key": "valid-key", | ||
}, | ||
}, | ||
response: { | ||
status: 204, | ||
}, | ||
handler: (req: MockRequest) => { | ||
req.expect.containsHeader("x-ms-api-key", "valid-key"); | ||
return { status: 204 }; | ||
}, | ||
); | ||
|
||
Scenarios.Authentication_ApiKey_valid = validAndInvalidScenarios.valid; | ||
kind: "MockApiDefinition", | ||
}); | ||
|
||
Scenarios.Authentication_ApiKey_invalid = validAndInvalidScenarios.invalid; | ||
Scenarios.Authentication_ApiKey_invalid = passOnSuccess({ | ||
uri: `/authentication/api-key/invalid`, | ||
method: `get`, | ||
request: { | ||
headers: { | ||
"x-ms-api-key": "valid-key", | ||
}, | ||
status: 403, | ||
}, | ||
response: { | ||
status: 403, | ||
body: json({ | ||
error: "invalid-api-key", | ||
}), | ||
}, | ||
handler: (req: MockRequest) => { | ||
return { | ||
status: 403, | ||
body: json({ | ||
error: "invalid-api-key", | ||
}), | ||
}; | ||
}, | ||
kind: "MockApiDefinition", | ||
}); |
51 changes: 41 additions & 10 deletions
51
packages/cadl-ranch-specs/http/authentication/http/custom/mockapi.ts
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,17 +1,48 @@ | ||
import { MockRequest } from "@azure-tools/cadl-ranch-api"; | ||
import { json, MockRequest, passOnSuccess } from "@azure-tools/cadl-ranch-api"; | ||
import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api"; | ||
import { getValidAndInvalidScenarios } from "../../commonapi.js"; | ||
|
||
export const Scenarios: Record<string, ScenarioMockApi> = {}; | ||
|
||
const validAndInvalidScenarios = getValidAndInvalidScenarios( | ||
"http/custom", | ||
"invalid-api-key", | ||
function addOptionalParamOldApiVersionNewClientValidate(req: MockRequest): void { | ||
Scenarios.Authentication_Http_Custom_valid = passOnSuccess({ | ||
uri: `/authentication/http/custom/valid`, | ||
method: "get", | ||
request: { | ||
headers: { | ||
authorization: "SharedAccessKey valid-key", | ||
}, | ||
}, | ||
response: { | ||
status: 204, | ||
}, | ||
handler: (req: MockRequest) => { | ||
req.expect.containsHeader("authorization", "SharedAccessKey valid-key"); | ||
return { status: 204 }; | ||
}, | ||
); | ||
|
||
Scenarios.Authentication_Http_Custom_valid = validAndInvalidScenarios.valid; | ||
kind: "MockApiDefinition", | ||
}); | ||
|
||
Scenarios.Authentication_Http_Custom_invalid = validAndInvalidScenarios.invalid; | ||
Scenarios.Authentication_Http_Custom_invalid = passOnSuccess({ | ||
uri: `/authentication/http/custom/invalid`, | ||
method: "get", | ||
request: { | ||
headers: { | ||
authorization: "SharedAccessKey valid-key", | ||
}, | ||
status: 403, | ||
}, | ||
response: { | ||
status: 403, | ||
body: json({ | ||
error: "invalid-api-key", | ||
}), | ||
}, | ||
handler: (req: MockRequest) => { | ||
return { | ||
status: 403, | ||
body: json({ | ||
error: "invalid-api-key", | ||
}), | ||
}; | ||
}, | ||
kind: "MockApiDefinition", | ||
}); |
48 changes: 38 additions & 10 deletions
48
packages/cadl-ranch-specs/http/authentication/oauth2/mockapi.ts
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,17 +1,45 @@ | ||
import { MockRequest } from "@azure-tools/cadl-ranch-api"; | ||
import { json, MockRequest, passOnSuccess } from "@azure-tools/cadl-ranch-api"; | ||
import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api"; | ||
import { getValidAndInvalidScenarios } from "../commonapi.js"; | ||
|
||
export const Scenarios: Record<string, ScenarioMockApi> = {}; | ||
|
||
const validAndInvalidScenarios = getValidAndInvalidScenarios( | ||
"oauth2", | ||
"invalid-grant", | ||
function addOptionalParamOldApiVersionNewClientValidate(req: MockRequest): void { | ||
Scenarios.Authentication_OAuth2_valid = passOnSuccess({ | ||
uri: `/authentication/oauth2/valid`, | ||
method: "get", | ||
request: { | ||
headers: { | ||
authorization: "Bearer https://security.microsoft.com/.default", | ||
}, | ||
}, | ||
response: { | ||
status: 204, | ||
}, | ||
handler: (req: MockRequest) => { | ||
req.expect.containsHeader("authorization", "Bearer https://security.microsoft.com/.default"); | ||
return { status: 204 }; | ||
}, | ||
); | ||
|
||
Scenarios.Authentication_OAuth2_valid = validAndInvalidScenarios.valid; | ||
kind: "MockApiDefinition", | ||
}); | ||
|
||
Scenarios.Authentication_OAuth2_invalid = validAndInvalidScenarios.invalid; | ||
Scenarios.Authentication_OAuth2_invalid = passOnSuccess({ | ||
uri: `/authentication/oauth2/invalid`, | ||
method: "get", | ||
request: { | ||
status: 403, | ||
}, | ||
response: { | ||
status: 403, | ||
body: json({ | ||
error: "invalid-grant", | ||
}), | ||
}, | ||
handler: (req: MockRequest) => { | ||
return { | ||
status: 403, | ||
body: json({ | ||
error: "invalid-grant", | ||
}), | ||
}; | ||
}, | ||
kind: "MockApiDefinition", | ||
}); |
40 changes: 31 additions & 9 deletions
40
packages/cadl-ranch-specs/http/authentication/union/mockapi.ts
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,18 +1,40 @@ | ||
import { passOnSuccess, mockapi } from "@azure-tools/cadl-ranch-api"; | ||
import { passOnSuccess, MockRequest } from "@azure-tools/cadl-ranch-api"; | ||
import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api"; | ||
|
||
export const Scenarios: Record<string, ScenarioMockApi> = {}; | ||
|
||
Scenarios.Authentication_Union_validKey = passOnSuccess( | ||
mockapi.get("/authentication/union/validkey", (req) => { | ||
Scenarios.Authentication_Union_validKey = passOnSuccess({ | ||
uri: `/authentication/union/validkey`, | ||
method: "get", | ||
request: { | ||
headers: { | ||
"x-ms-api-key": "valid-key", | ||
}, | ||
}, | ||
response: { | ||
status: 204, | ||
}, | ||
handler: (req: MockRequest) => { | ||
req.expect.containsHeader("x-ms-api-key", "valid-key"); | ||
return { status: 204 }; | ||
}), | ||
); | ||
}, | ||
kind: "MockApiDefinition", | ||
}); | ||
|
||
Scenarios.Authentication_Union_validToken = passOnSuccess( | ||
mockapi.get("/authentication/union/validtoken", (req) => { | ||
Scenarios.Authentication_Union_validToken = passOnSuccess({ | ||
uri: `/authentication/union/validtoken`, | ||
method: "get", | ||
request: { | ||
headers: { | ||
authorization: "Bearer https://security.microsoft.com/.default", | ||
}, | ||
}, | ||
response: { | ||
status: 204, | ||
}, | ||
handler: (req: MockRequest) => { | ||
req.expect.containsHeader("authorization", "Bearer https://security.microsoft.com/.default"); | ||
return { status: 204 }; | ||
}), | ||
); | ||
}, | ||
kind: "MockApiDefinition", | ||
}); |
Oops, something went wrong.