From 1c238f82cbf9157c7c09f7a7ce3be10d0dd1d6d0 Mon Sep 17 00:00:00 2001 From: Larry Osterman Date: Fri, 9 Jul 2021 16:06:03 -0700 Subject: [PATCH] Renamed `any` types to be `unknown` (#16344) * renamed `any` types to be `unknown` * Fixed overagressive code change --- .../attestation/review/attestation.api.md | 10 ++--- .../attestation/src/attestationClient.ts | 5 ++- .../src/models/attestationResult.ts | 42 +++++++++---------- .../src/models/attestationToken.ts | 4 +- .../test/public/attestationTests.spec.ts | 23 +++++----- 5 files changed, 44 insertions(+), 40 deletions(-) diff --git a/sdk/attestation/attestation/review/attestation.api.md b/sdk/attestation/attestation/review/attestation.api.md index ac7a86af18bd..bf246e563ced 100644 --- a/sdk/attestation/attestation/review/attestation.api.md +++ b/sdk/attestation/attestation/review/attestation.api.md @@ -36,7 +36,7 @@ export class AttestationClient { attestSgxEnclave(quote: Uint8Array, options?: AttestSgxEnclaveOptions): Promise>; attestTpm(request: string, options?: AttestTpmOptions): Promise; getAttestationSigners(options?: AttestationClientOperationOptions): Promise; - getOpenIdMetadata(options?: AttestationClientOperationOptions): Promise; + getOpenIdMetadata(options?: AttestationClientOperationOptions): Promise>; } // @public @@ -62,17 +62,17 @@ export interface AttestationResponse { // @public export interface AttestationResult { enclaveHeldData?: Uint8Array; - inittimeClaims: any; + initTimeClaims: unknown; isDebuggable?: boolean; issuer: string; mrEnclave?: string; mrSigner?: string; nonce?: string; - policyClaims: any; + policyClaims: unknown; policyHash: Uint8Array; policySigner?: AttestationSigner; productId?: number; - runtimeClaims: any; + runTimeClaims: unknown; sgxCollateral?: AttestationSgxCollateralInfo; svn?: number; uniqueId: string; @@ -106,7 +106,7 @@ export interface AttestationToken { contentType?: string; critical?: boolean; expiresOn?: Date; - getBody(): any; + getBody(): unknown; issuedAt?: Date; issuer?: string; keyId?: string; diff --git a/sdk/attestation/attestation/src/attestationClient.ts b/sdk/attestation/attestation/src/attestationClient.ts index 45c95f37fa3a..4e2d300fbabb 100644 --- a/sdk/attestation/attestation/src/attestationClient.ts +++ b/sdk/attestation/attestation/src/attestationClient.ts @@ -449,13 +449,16 @@ export class AttestationClient { * @param options - Client operation options. * @returns The OpenID metadata discovery document for the attestation service. */ - public async getOpenIdMetadata(options: AttestationClientOperationOptions = {}): Promise { + public async getOpenIdMetadata( + options: AttestationClientOperationOptions = {} + ): Promise> { const { span, updatedOptions } = createSpan("AttestationClient-getOpenIdMetadata", options); try { const configs = await this._client.metadataConfiguration.get(updatedOptions); return configs; } catch (e) { span.setStatus({ code: SpanStatusCode.ERROR, message: e.message }); + throw e; } finally { span.end(); } diff --git a/sdk/attestation/attestation/src/models/attestationResult.ts b/sdk/attestation/attestation/src/models/attestationResult.ts index bc0420a89b9f..bd3522dd5a47 100644 --- a/sdk/attestation/attestation/src/models/attestationResult.ts +++ b/sdk/attestation/attestation/src/models/attestationResult.ts @@ -103,7 +103,7 @@ export interface AttestationResult { * `runtimeJson` parameter to the `Attest` API is specified. It will * not be populated if the `runtimeData` parameter is specified. */ - runtimeClaims: any; + runTimeClaims: unknown; /** * Returns the initialization time claims in the token. * This value will match the input `initTimeJson` property to the @@ -116,12 +116,12 @@ export interface AttestationResult { * parameter to the `Attest` API is specified. It will not be populated if * the `initTimeData` parameter is specified. */ - inittimeClaims: any; + initTimeClaims: unknown; /** * Returns the set of claims generated by the attestation policy on the instance. */ - policyClaims: any; + policyClaims: unknown; /** * Returns the verifier which generated this attestation token. Normally one of: @@ -199,9 +199,9 @@ export class AttestationResultImpl implements AttestationResult { version: string; nonce?: string; uniqueId: string; - runtimeClaims?: any; - inittimeClaims?: any; - policyClaims?: any; + runTimeClaims?: unknown; + initTimeClaims?: unknown; + policyClaims?: unknown; verifierType: string; policySigner?: AttestationSigner; policyHash: Uint8Array; @@ -211,14 +211,14 @@ export class AttestationResultImpl implements AttestationResult { mrSigner?: string; svn?: number; enclaveHeldData?: Uint8Array; - sgxCollateral?: any; + sgxCollateral?: AttestationSgxCollateralInfo; }) { this._issuer = params.issuer; this._nonce = params.nonce; this._version = params.version; this._uniqueId = params.uniqueId; - this._runtimeClaims = params.runtimeClaims; - this._inittimeClaims = params.inittimeClaims; + this._runTimeClaims = params.runTimeClaims; + this._initTimeClaims = params.initTimeClaims; this._policyClaims = params.policyClaims; this._verifierType = params.verifierType; this._policySigner = params.policySigner; @@ -236,9 +236,9 @@ export class AttestationResultImpl implements AttestationResult { private _version: string; private _nonce?: string; private _uniqueId: string; - private _runtimeClaims?: any; - private _inittimeClaims?: any; - private _policyClaims?: any; + private _runTimeClaims?: unknown; + private _initTimeClaims?: unknown; + private _policyClaims?: unknown; private _verifierType: string; private _policySigner?: AttestationSigner; private _policyHash: Uint8Array; @@ -248,7 +248,7 @@ export class AttestationResultImpl implements AttestationResult { private _mrSigner?: string; private _svn?: number; private _enclaveHeldData?: Uint8Array; - private _sgxCollateral?: any; + private _sgxCollateral?: AttestationSgxCollateralInfo; /** * Unique Identifier for the token @@ -283,20 +283,20 @@ export class AttestationResultImpl implements AttestationResult { /** * Runtime Claims */ - get runtimeClaims(): any { - return this._runtimeClaims; + get runTimeClaims(): unknown { + return this._runTimeClaims; } /** * Inittime Claims */ - get inittimeClaims(): any { - return this._inittimeClaims; + get initTimeClaims(): unknown { + return this._initTimeClaims; } /** * Policy Generated Claims */ - get policyClaims(): any { + get policyClaims(): unknown { return this._policyClaims; } /** @@ -356,7 +356,7 @@ export class AttestationResultImpl implements AttestationResult { /** * The SGX SVN value for the enclave. */ - get sgxCollateral(): any { + get sgxCollateral(): AttestationSgxCollateralInfo | undefined { return this._sgxCollateral; } } @@ -379,8 +379,8 @@ export function _attestationResultFromGenerated( policySigner: generated.policySigner ? _attestationSignerFromGenerated(generated.policySigner) : undefined, - runtimeClaims: generated.runtimeClaims, - inittimeClaims: generated.inittimeClaims, + runTimeClaims: generated.runtimeClaims, + initTimeClaims: generated.inittimeClaims, policyClaims: generated.policyClaims, verifierType: generated.verifierType, policyHash: generated.policyHash, diff --git a/sdk/attestation/attestation/src/models/attestationToken.ts b/sdk/attestation/attestation/src/models/attestationToken.ts index 03e6aaae835c..08b827a72992 100644 --- a/sdk/attestation/attestation/src/models/attestationToken.ts +++ b/sdk/attestation/attestation/src/models/attestationToken.ts @@ -84,7 +84,7 @@ export interface AttestationToken { * * @returns The body of the attestation token as an object. */ - getBody(): any; + getBody(): unknown; /** * the token to a string. @@ -258,7 +258,7 @@ export class AttestationTokenImpl implements AttestationToken { * * @returns The body of the attestation token as an object. */ - public getBody(): any { + public getBody(): unknown { return this._jwsVerifier.payloadObj; } diff --git a/sdk/attestation/attestation/test/public/attestationTests.spec.ts b/sdk/attestation/attestation/test/public/attestationTests.spec.ts index 6f9c57c96bc5..6ce74b002299 100644 --- a/sdk/attestation/attestation/test/public/attestationTests.spec.ts +++ b/sdk/attestation/attestation/test/public/attestationTests.spec.ts @@ -225,7 +225,7 @@ describe("[AAD] Attestation Client", function() { ); assert.isNotNull(attestationResult.body.sgxCollateral); - assert.isUndefined(attestationResult.body.runtimeClaims); + assert.isUndefined(attestationResult.body.runTimeClaims); expect(attestationResult.body.enclaveHeldData?.length).is.equal(binaryRuntimeData.length); expect(attestationResult.body.enclaveHeldData).to.deep.equal(binaryRuntimeData); @@ -241,14 +241,15 @@ describe("[AAD] Attestation Client", function() { ); assert.isNotNull(attestationResult.body.sgxCollateral); - assert.isDefined(attestationResult.body.runtimeClaims); + assert.isDefined(attestationResult.body.runTimeClaims); assert.isUndefined(attestationResult.body.enclaveHeldData); // Confirm that the JWK response out of the service makes sense and contains // the JSON inside the binaryRuntimeData. - assert.isDefined(attestationResult.body.runtimeClaims.jwk); - assert.isDefined(attestationResult.body.runtimeClaims.jwk.crv); - expect(attestationResult.body.runtimeClaims.jwk.crv).is.equal("P-256"); + const runtimeClaims = attestationResult.body.runTimeClaims as any; + assert.isDefined(runtimeClaims.jwk); + assert.isDefined(runtimeClaims.jwk.crv); + expect(runtimeClaims.jwk.crv).is.equal("P-256"); assert(attestationResult.token, "Expected a token from the service but did not receive one"); } @@ -290,10 +291,9 @@ describe("[AAD] Attestation Client", function() { ); assert.isNotNull(attestationResult.body.sgxCollateral); - assert.isUndefined(attestationResult.body.runtimeClaims); + assert.isUndefined(attestationResult.body.runTimeClaims); expect(attestationResult.body.enclaveHeldData?.length).is.equal(binaryRuntimeData.length); expect(attestationResult.body.enclaveHeldData).to.deep.equal(binaryRuntimeData); - assert(attestationResult.token, "Expected a token from the service but did not receive one"); } @@ -309,14 +309,15 @@ describe("[AAD] Attestation Client", function() { ); assert.isNotNull(attestationResult.body.sgxCollateral); - assert.isDefined(attestationResult.body.runtimeClaims); + assert.isDefined(attestationResult.body.runTimeClaims); assert.isUndefined(attestationResult.body.enclaveHeldData); // Confirm that the JWK response out of the service makes sense and contains // the JSON inside the binaryRuntimeData. - assert.isDefined(attestationResult.body.runtimeClaims.jwk); - assert.isDefined(attestationResult.body.runtimeClaims.jwk.crv); - expect(attestationResult.body.runtimeClaims.jwk.crv).is.equal("P-256"); + const runtimeClaims = attestationResult.body.runTimeClaims as any; + assert.isDefined(runtimeClaims.jwk); + assert.isDefined(runtimeClaims.jwk.crv); + expect(runtimeClaims.jwk.crv).is.equal("P-256"); assert(attestationResult.token, "Expected a token from the service but did not receive one"); }