Skip to content

Commit

Permalink
[attestation] Precise Typechecking (#32150)
Browse files Browse the repository at this point in the history
### Packages impacted by this PR
- @azure/attestation

### Issues associated with this PR
N/A

### Describe the problem that is addressed by this PR
Tests are not being typechecked and linting isn't configured correctly.
This PR migrates those libraries to precise typechecking setup
introduced in #31786

### What are the possible designs available to address the problem? If
there are more than one possible design, why was the one in this PR
chosen?

### Are there test cases added in this PR? _(If not, why?)_
N/A

### Provide a list of related PRs _(if any)_
#31786

### Command used to generate this PR:**_(Applicable only to SDK release
request PRs)_

### Checklists
- [x] Added impacted package name to the issue description
- [ ] Does this PR needs any fixes in the SDK Generator?** _(If so,
create an Issue in the
[Autorest/typescript](https://github.com/Azure/autorest.typescript)
repository and link it here)_
- [ ] Added a changelog (if necessary)
  • Loading branch information
deyaaeldeen authored Dec 11, 2024
1 parent ec6a153 commit e3bcad0
Show file tree
Hide file tree
Showing 14 changed files with 66 additions and 32 deletions.
12 changes: 12 additions & 0 deletions sdk/attestation/attestation/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import azsdkEslint from "@azure/eslint-plugin-azure-sdk";

export default azsdkEslint.config([
{
files: ["**/*.ts", "**/*.cts", "**/*.mts"],
languageOptions: {
parserOptions: {
project: ["./tsconfig.test.json"],
},
},
},
]);
5 changes: 3 additions & 2 deletions sdk/attestation/attestation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"generate:client": "autorest --typescript ./swagger/README.md",
"integration-test": "npm run integration-test:node && npm run integration-test:browser",
"integration-test:browser": "dev-tool run test:vitest --browser",
"integration-test:node": "dev-tool run test:vitest -- --test-timeout 5000000",
"integration-test:node": "dev-tool run test:vitest --esm -- --test-timeout 5000000",
"lint": "eslint package.json api-extractor.json src test",
"lint:fix": "eslint package.json api-extractor.json src test --fix --fix-type [problem,suggestion]",
"pack": "npm pack 2>&1",
Expand Down Expand Up @@ -122,7 +122,8 @@
"browser",
"react-native"
],
"selfLink": false
"selfLink": false,
"project": "./tsconfig.src.json"
},
"exports": {
"./package.json": "./package.json",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@ import { X509 } from "jsrsasign";
// Load environment from a .env file if it exists.
import * as dotenv from "dotenv";
import { writeBanner } from "./utils/helpers.js";
import { byteArrayToHex } from "../src/utils/base64.js";
dotenv.config();

function byteArrayToHex(value: Uint8Array): string {
return value.reduce((str, byte) => str + byte.toString(16).padStart(2, "0"), "");
}

async function modifyPolicyManagementCertificates() {
writeBanner("Get Current Attestation Policy Management Certificates.");

Expand Down
11 changes: 10 additions & 1 deletion sdk/attestation/attestation/samples-dev/utils/cryptoUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,16 @@
/// <reference path="../../src/jsrsasign.d.ts"/>
import * as jsrsasign from "jsrsasign";

import { hexToByteArray } from "../../src/utils/base64.js";
function hexToByteArray(value: string): Uint8Array {
if (value.length % 2 !== 0) {
throw new Error("base64FromHex: Input must be a multiple of 2 characters");
}
const byteArray = new Array();
for (let i = 0; i < value.length; i += 2) {
byteArray.push(parseInt(value.substr(i, 2), 16));
}
return Uint8Array.from(byteArray);
}

export function createECDSKey(): [string, string] {
const keyPair = jsrsasign.KEYUTIL.generateKeypair("EC", "secp256r1");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import type { TokenCredential } from "@azure/core-auth";
import { TypeDeserializer } from "./utils/typeDeserializer.js";
import * as Mappers from "./generated/models/mappers.js";

// eslint-disable-next-line @typescript-eslint/triple-slash-reference
/// <reference path="../jsrsasign.d.ts"/>
import * as jsrsasign from "jsrsasign";
import { hexToBase64 } from "./utils/helpers.js";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
// eslint-disable-next-line @typescript-eslint/triple-slash-reference
/// <reference path="../../src/jsrsasign.d.ts"/>
import * as jsrsasign from "jsrsasign";
/* eslint-disable @typescript-eslint/no-invalid-this */

import { Recorder, isLiveMode } from "@azure-tools/test-recorder";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
/* eslint-disable @typescript-eslint/no-invalid-this */

import { Recorder, isLiveMode } from "@azure-tools/test-recorder";

Expand All @@ -12,7 +11,6 @@ import {
import { createRSAKey, createX509Certificate, generateSha1Hash } from "../utils/cryptoUtils.js";
import { KnownCertificateModification } from "../../src/generated/index.js";

// eslint-disable-next-line @typescript-eslint/triple-slash-reference
/// <reference path="../jsrsasign.d.ts"/>
import * as jsrsasign from "jsrsasign";
import { byteArrayToHex } from "../../src/utils/base64.js";
Expand Down
9 changes: 1 addition & 8 deletions sdk/attestation/attestation/tsconfig.browser.config.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
{
"extends": "./.tshy/build.json",
"include": ["./src/**/*.ts", "./src/**/*.mts", "./test/**/*.spec.ts", "./test/**/*.mts"],
"exclude": ["./test/**/node/**/*.ts"],
"compilerOptions": {
"outDir": "./dist-test/browser",
"rootDir": ".",
"skipLibCheck": true
}
"extends": ["./tsconfig.test.json", "../../../tsconfig.browser.base.json"]
}
22 changes: 6 additions & 16 deletions sdk/attestation/attestation/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
{
"extends": "../../../tsconfig",
"compilerOptions": {
"paths": {
"@azure/attestation": ["./src/index"]
},
"module": "NodeNext",
"moduleResolution": "NodeNext",
"rootDir": "."
},
"include": [
"src/**/*.ts",
"src/**/*.mts",
"src/**/*.cts",
"samples-dev/**/*.ts",
"test/**/*.ts",
"test/**/*.mts"
]
"references": [
{ "path": "./tsconfig.src.json" },
{ "path": "./tsconfig.samples.json" },
{ "path": "./tsconfig.test.json" }
],
"files": []
}
8 changes: 8 additions & 0 deletions sdk/attestation/attestation/tsconfig.samples.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../../tsconfig.samples.base.json",
"compilerOptions": {
"paths": {
"@azure/attestation": ["./dist/esm"]
}
}
}
3 changes: 3 additions & 0 deletions sdk/attestation/attestation/tsconfig.src.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../../tsconfig.lib.json"
}
3 changes: 3 additions & 0 deletions sdk/attestation/attestation/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["./tsconfig.src.json", "../../../tsconfig.test.base.json"]
}
5 changes: 5 additions & 0 deletions sdk/attestation/attestation/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ export default mergeConfig(
defineConfig({
test: {
include: ["test/**/*.spec.ts"],
typecheck: {
enabled: true,
tsconfig: "tsconfig.test.json",
include: ["test/**/*.ts", "test/**/*.mts", "test/**/*.cts"],
},
},
}),
);
11 changes: 11 additions & 0 deletions sdk/attestation/attestation/vitest.esm.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { mergeConfig } from "vitest/config";
import vitestConfig from "./vitest.config.ts";
import vitestEsmConfig from "../../../vitest.esm.shared.config.ts";

export default mergeConfig(
vitestConfig,
vitestEsmConfig
);

0 comments on commit e3bcad0

Please sign in to comment.