specs, fix mockapi in auth scenarios (#752)

This commit is contained in:
Weidong Xu 2024-10-16 10:38:48 +08:00 коммит произвёл GitHub
Родитель afce8beb1b
Коммит 46e3022589
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
7 изменённых файлов: 15 добавлений и 12 удалений

Просмотреть файл

@ -0,0 +1,6 @@
---
"@azure-tools/cadl-ranch-api": minor
"@azure-tools/cadl-ranch-specs": patch
---
Fix mockapi in authentication scenarios.

Просмотреть файл

@ -1,7 +1,6 @@
import {
KeyedMockApi,
KeyedMockApiDefinition,
KeyedMockRequestHandler,
MockApi,
MockApiDefinition,
PassByKeyScenario,
@ -27,7 +26,7 @@ export function passOnSuccess(
* @param code Status code all endpoint should return
* @param apis Endpoint or List of endpoints for this scenario
*/
export function passOnCode(code: number, apis: MockApi | readonly MockApi[]): PassOnCodeScenario {
export function passOnCode(code: number, apis: MockApi | readonly MockApi[] | MockApiDefinition): PassOnCodeScenario {
return {
passCondition: "status-code",
code,

Просмотреть файл

@ -1,4 +1,4 @@
import { json, MockRequest, passOnSuccess } from "@azure-tools/cadl-ranch-api";
import { json, MockRequest, passOnCode, passOnSuccess } from "@azure-tools/cadl-ranch-api";
import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api";
export const Scenarios: Record<string, ScenarioMockApi> = {};
@ -21,12 +21,12 @@ Scenarios.Authentication_ApiKey_valid = passOnSuccess({
kind: "MockApiDefinition",
});
Scenarios.Authentication_ApiKey_invalid = passOnSuccess({
Scenarios.Authentication_ApiKey_invalid = passOnCode(403, {
uri: `/authentication/api-key/invalid`,
method: `get`,
request: {
headers: {
"x-ms-api-key": "valid-key",
"x-ms-api-key": "invalid-key",
},
status: 403,
},

Просмотреть файл

@ -1,4 +1,4 @@
import { json, MockRequest, passOnSuccess } from "@azure-tools/cadl-ranch-api";
import { json, MockRequest, passOnSuccess, passOnCode } from "@azure-tools/cadl-ranch-api";
import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api";
export const Scenarios: Record<string, ScenarioMockApi> = {};
@ -21,12 +21,12 @@ Scenarios.Authentication_Http_Custom_valid = passOnSuccess({
kind: "MockApiDefinition",
});
Scenarios.Authentication_Http_Custom_invalid = passOnSuccess({
Scenarios.Authentication_Http_Custom_invalid = passOnCode(403, {
uri: `/authentication/http/custom/invalid`,
method: "get",
request: {
headers: {
authorization: "SharedAccessKey valid-key",
authorization: "SharedAccessKey invalid-key",
},
status: 403,
},

Просмотреть файл

@ -1,4 +1,4 @@
import { json, MockRequest, passOnSuccess } from "@azure-tools/cadl-ranch-api";
import { json, MockRequest, passOnSuccess, passOnCode } from "@azure-tools/cadl-ranch-api";
import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api";
export const Scenarios: Record<string, ScenarioMockApi> = {};
@ -21,7 +21,7 @@ Scenarios.Authentication_OAuth2_valid = passOnSuccess({
kind: "MockApiDefinition",
});
Scenarios.Authentication_OAuth2_invalid = passOnSuccess({
Scenarios.Authentication_OAuth2_invalid = passOnCode(403, {
uri: `/authentication/oauth2/invalid`,
method: "get",
request: {

Просмотреть файл

@ -1,6 +1,5 @@
import { passOnSuccess, json, MockApiDefinition, MockRequest } from "@azure-tools/cadl-ranch-api";
import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api";
import { Mock } from "node:test";
export const Scenarios: Record<string, ScenarioMockApi> = {};
function createMockApiDefinitions(route: string, request: any, response: any): MockApiDefinition {

Просмотреть файл

@ -1,6 +1,5 @@
import { passOnSuccess, json, MockRequest } from "@azure-tools/cadl-ranch-api";
import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api";
import { Mock } from "node:test";
export const Scenarios: Record<string, ScenarioMockApi> = {};