-
Notifications
You must be signed in to change notification settings - Fork 230
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
1 parent
24ce55f
commit 2c69493
Showing
2 changed files
with
42 additions
and
1 deletion.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
packages/http-client-csharp/emitter/test/Unit/auth.test.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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { TestHost } from "@typespec/compiler/testing"; | ||
import { ok, strictEqual } from "assert"; | ||
import { beforeEach, describe, it } from "vitest"; | ||
import { createModel } from "../../src/lib/client-model-builder.js"; | ||
import { | ||
createEmitterContext, | ||
createEmitterTestHost, | ||
createNetSdkContext, | ||
typeSpecCompile, | ||
} from "./utils/test-util.js"; | ||
|
||
describe("Test auth", () => { | ||
let runner: TestHost; | ||
|
||
beforeEach(async () => { | ||
runner = await createEmitterTestHost(); | ||
}); | ||
|
||
it("cookie header is not supported", async () => { | ||
const program = await typeSpecCompile( | ||
` | ||
op test(): NoContentResponse; | ||
`, | ||
runner, | ||
{ | ||
AuthDecorator: `@useAuth(ApiKeyAuth<ApiKeyLocation.cookie, "api-key-name">)`, | ||
} | ||
); | ||
const context = createEmitterContext(program); | ||
const sdkContext = await createNetSdkContext(context); | ||
const root = createModel(sdkContext); | ||
const diagnostics = context.program.diagnostics; | ||
|
||
const noAuthDiagnostic = diagnostics.find((d) => d.code === "@typespec/http-client-csharp/unsupported-auth"); | ||
ok(noAuthDiagnostic); | ||
strictEqual(noAuthDiagnostic.message, "Only header is supported for ApiKey authentication. cookie is not supported."); | ||
strictEqual(root.Auth, undefined); // we do not support it therefore it falls back to undefined | ||
}); | ||
}); |
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