From 5ade082b97f4223ad2616d0906a1e4d0f45ef454 Mon Sep 17 00:00:00 2001 From: Somanath Chavan Date: Wed, 15 Feb 2023 14:00:41 +0000 Subject: [PATCH] iam identity user mfa Signed-off-by: Somanath Chavan --- examples/iam-identity.v1.test.js | 94 ++++++- iam-identity/v1.ts | 335 +++++++++++++++++++++-- test/integration/iam-identity.v1.test.js | 63 ++++- test/unit/iam-identity.v1.test.js | 273 +++++++++++++++++- 4 files changed, 732 insertions(+), 33 deletions(-) diff --git a/examples/iam-identity.v1.test.js b/examples/iam-identity.v1.test.js index 266ebf3e..15a7be31 100644 --- a/examples/iam-identity.v1.test.js +++ b/examples/iam-identity.v1.test.js @@ -86,6 +86,7 @@ describe('IamIdentityV1', () => { let accountSettingsEtag = null; let reportReference = null; + let reportReferenceMfa=null; test('createApiKey request example', async () => { @@ -1013,14 +1014,14 @@ describe('IamIdentityV1', () => { const params = { ifMatch: accountSettingsEtag, accountId: accountId, - restrict_create_service_id: "NOT_RESTRICTED", - restrict_create_platform_apikey: "NOT_RESTRICTED", + restrictCreateServiceId: "NOT_RESTRICTED", + restrictCreatePlatformApikey: "NOT_RESTRICTED", mfa: "NONE", userMfa, - session_expiration_in_seconds: "86400", - session_invalidation_in_seconds: "7200", - system_access_token_expiration_in_seconds: '3600', - system_refresh_token_expiration_in_seconds: '2592000', + sessionExpirationInSeconds: "86400", + sessionInvalidationInSeconds: "7200", + systemAccessTokenExpirationInSeconds: '3600', + systemRefreshTokenExpirationInSeconds: '259200', }; try { @@ -1054,7 +1055,7 @@ describe('IamIdentityV1', () => { try { const res = await iamIdentityService.createReport(params); reportReference = res.reference; - console.log(JSON.stringify(reportReference, null, 2)); + console.log(JSON.stringify(res.result, null, 2)); } catch (err) { console.warn(err); } @@ -1086,4 +1087,83 @@ describe('IamIdentityV1', () => { } // end-get_report }); + test('createMfaReport request example', async () => { + + consoleLogMock.mockImplementation(output => { + originalLog(output); + }); + consoleWarnMock.mockImplementation(output => { + originalWarn(output); + expect(true).toBeFalsy(); + }); + + originalLog('createMfaReport() result:'); + // begin-create_mfa_report + + const params = { + accountId: accountId, + type: 'mfa_status', + }; + + try { + const res = await iamIdentityService.createMfaReport(params); + reportReferenceMfa = res.result.reference; + console.log(JSON.stringify(res.result, null, 2)); + } catch (err) { + console.warn(err); + } + // end-create_mfa_report + }); + test('getMfaReport request example', async () => { + + consoleLogMock.mockImplementation(output => { + originalLog(output); + }); + consoleWarnMock.mockImplementation(output => { + originalWarn(output); + expect(true).toBeFalsy(); + }); + + originalLog('getMfaReport() result:'); + // begin-get_mfa_report + + const params = { + accountId: accountId, + reference: 'latest', + }; + + try { + const res = await iamIdentityService.getMfaReport(params); + console.log(JSON.stringify(res.result, null, 2)); + } catch (err) { + console.warn(err); + } + // end-get_mfa_report + }); + test('getMfaStatus request example', async () => { + + consoleLogMock.mockImplementation(output => { + originalLog(output); + }); + consoleWarnMock.mockImplementation(output => { + originalWarn(output); + expect(true).toBeFalsy(); + }); + + originalLog('getMfaStatus() result:'); + // begin-get_mfa_status + + const params = { + accountId: accountId, + iamId: iamId, + }; + + try { + const res = await iamIdentityService.getMfaStatus(params); + console.log(JSON.stringify(res.result, null, 2)); + } catch (err) { + console.warn(err); + } + // end-get_mfa_status + }); }); diff --git a/iam-identity/v1.ts b/iam-identity/v1.ts index 5881a5a1..552a12bc 100644 --- a/iam-identity/v1.ts +++ b/iam-identity/v1.ts @@ -1,5 +1,5 @@ /** - * (C) Copyright IBM Corp. 2022. + * (C) Copyright IBM Corp. 2023. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ */ /** - * IBM OpenAPI SDK Code Generator Version: 3.62.0-a2a22f95-20221115-162524 + * IBM OpenAPI SDK Code Generator Version: 3.64.0-959a5845-20230112-195144 */ import * as extend from 'extend'; @@ -93,7 +93,7 @@ class IamIdentityV1 extends BaseService { } /************************* - * APIKeyOperations + * aPIKeyOperations ************************/ /** @@ -105,18 +105,18 @@ class IamIdentityV1 extends BaseService { * space developer in order to manage service IDs of the entity. * * @param {Object} [params] - The parameters to send to the service. - * @param {string} [params.accountId] - Account ID of the API keys(s) to query. If a service IAM ID is specified in + * @param {string} [params.accountId] - Account ID of the API keys to query. If a service IAM ID is specified in * iam_id then account_id must match the account of the IAM ID. If a user IAM ID is specified in iam_id then then * account_id must match the account of the Authorization token. - * @param {string} [params.iamId] - IAM ID of the API key(s) to be queried. The IAM ID may be that of a user or a + * @param {string} [params.iamId] - IAM ID of the API keys to be queried. The IAM ID may be that of a user or a * service. For a user IAM ID iam_id must match the Authorization token. * @param {number} [params.pagesize] - Optional size of a single page. Default is 20 items per page. Valid range is 1 * to 100. * @param {string} [params.pagetoken] - Optional Prev or Next page token returned from a previous query execution. * Default is start with first page. - * @param {string} [params.scope] - Optional parameter to define the scope of the queried API Keys. Can be 'entity' + * @param {string} [params.scope] - Optional parameter to define the scope of the queried API keys. Can be 'entity' * (default) or 'account'. - * @param {string} [params.type] - Optional parameter to filter the type of the queried API Keys. Can be 'user' or + * @param {string} [params.type] - Optional parameter to filter the type of the queried API keys. Can be 'user' or * 'serviceid'. * @param {string} [params.sort] - Optional sort property, valid values are name, description, created_at and * created_by. If specified, the items are sorted by the value of this property. @@ -723,7 +723,7 @@ class IamIdentityV1 extends BaseService { * * Returns the details of a service ID. Users can manage user API keys for themself, or service ID API keys for * service IDs that are bound to an entity they have access to. Note: apikey details are only included in the response - * when creating a Service ID with an apikey. + * when creating a Service ID with an api key. * * @param {Object} params - The parameters to send to the service. * @param {string} params.id - Unique ID of the service ID. @@ -1846,8 +1846,8 @@ class IamIdentityV1 extends BaseService { /** * Update account configurations. * - * Allows a user to configure settings on their account with regards to MFA, session lifetimes, access control for - * creating new identities, and enforcing IP restrictions on token creation. + * Allows a user to configure settings on their account with regards to MFA, MFA excemption list, session lifetimes, + * access control for creating new identities, and enforcing IP restrictions on token creation. * * @param {Object} params - The parameters to send to the service. * @param {string} params.ifMatch - Version of the account settings to be updated. Specify the version that you @@ -1893,7 +1893,7 @@ class IamIdentityV1 extends BaseService { * * NOT_SET - To unset account setting and use service default. * @param {string} [params.systemRefreshTokenExpirationInSeconds] - Defines the refresh token expiration in seconds. * Valid values: - * * Any whole number between '900' and '2592000' + * * Any whole number between '900' and '259200' * * NOT_SET - To unset account setting and use service default. * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers * @returns {Promise>} @@ -1969,6 +1969,171 @@ class IamIdentityV1 extends BaseService { return this.createRequest(parameters); } + /************************* + * mFAEnrollmentStatus + ************************/ + + /** + * Get MFA enrollment status for a single user in the account. + * + * Get MFA enrollment status for a single user in the account. + * + * @param {Object} params - The parameters to send to the service. + * @param {string} params.accountId - ID of the account. + * @param {string} params.iamId - iam_id of the user. This user must be the member of the account. + * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers + * @returns {Promise>} + */ + public getMfaStatus( + params: IamIdentityV1.GetMfaStatusParams + ): Promise> { + const _params = { ...params }; + const _requiredParams = ['accountId', 'iamId']; + const _validParams = ['accountId', 'iamId', 'headers']; + const _validationErrors = validateParams(_params, _requiredParams, _validParams); + if (_validationErrors) { + return Promise.reject(_validationErrors); + } + + const query = { + 'iam_id': _params.iamId, + }; + + const path = { + 'account_id': _params.accountId, + }; + + const sdkHeaders = getSdkHeaders(IamIdentityV1.DEFAULT_SERVICE_NAME, 'v1', 'getMfaStatus'); + + const parameters = { + options: { + url: '/v1/mfa/accounts/{account_id}/status', + method: 'GET', + qs: query, + path, + }, + defaultOptions: extend(true, {}, this.baseOptions, { + headers: extend( + true, + sdkHeaders, + { + 'Accept': 'application/json', + }, + _params.headers + ), + }), + }; + + return this.createRequest(parameters); + } + + /** + * Trigger MFA enrollment status report for the account. + * + * Trigger MFA enrollment status report for the account by specifying the account ID. It can take a few minutes to + * generate the report for retrieval. + * + * @param {Object} params - The parameters to send to the service. + * @param {string} params.accountId - ID of the account. + * @param {string} [params.type] - Optional report type. The supported value is 'mfa_status'. List MFA enrollment + * status for all the identities. + * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers + * @returns {Promise>} + */ + public createMfaReport( + params: IamIdentityV1.CreateMfaReportParams + ): Promise> { + const _params = { ...params }; + const _requiredParams = ['accountId']; + const _validParams = ['accountId', 'type', 'headers']; + const _validationErrors = validateParams(_params, _requiredParams, _validParams); + if (_validationErrors) { + return Promise.reject(_validationErrors); + } + + const query = { + 'type': _params.type, + }; + + const path = { + 'account_id': _params.accountId, + }; + + const sdkHeaders = getSdkHeaders(IamIdentityV1.DEFAULT_SERVICE_NAME, 'v1', 'createMfaReport'); + + const parameters = { + options: { + url: '/v1/mfa/accounts/{account_id}/report', + method: 'POST', + qs: query, + path, + }, + defaultOptions: extend(true, {}, this.baseOptions, { + headers: extend( + true, + sdkHeaders, + { + 'Accept': 'application/json', + }, + _params.headers + ), + }), + }; + + return this.createRequest(parameters); + } + + /** + * Get MFA enrollment status report for the account. + * + * Get MFA enrollment status report for the account by specifying the account ID and the reference that is generated + * by triggering the report. Reports older than a day are deleted when generating a new report. + * + * @param {Object} params - The parameters to send to the service. + * @param {string} params.accountId - ID of the account. + * @param {string} params.reference - Reference for the report to be generated, You can use 'latest' to get the latest + * report for the given account. + * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers + * @returns {Promise>} + */ + public getMfaReport( + params: IamIdentityV1.GetMfaReportParams + ): Promise> { + const _params = { ...params }; + const _requiredParams = ['accountId', 'reference']; + const _validParams = ['accountId', 'reference', 'headers']; + const _validationErrors = validateParams(_params, _requiredParams, _validParams); + if (_validationErrors) { + return Promise.reject(_validationErrors); + } + + const path = { + 'account_id': _params.accountId, + 'reference': _params.reference, + }; + + const sdkHeaders = getSdkHeaders(IamIdentityV1.DEFAULT_SERVICE_NAME, 'v1', 'getMfaReport'); + + const parameters = { + options: { + url: '/v1/mfa/accounts/{account_id}/report/{reference}', + method: 'GET', + path, + }, + defaultOptions: extend(true, {}, this.baseOptions, { + headers: extend( + true, + sdkHeaders, + { + 'Accept': 'application/json', + }, + _params.headers + ), + }), + }; + + return this.createRequest(parameters); + } /************************* * activityOperations ************************/ @@ -2114,12 +2279,12 @@ namespace IamIdentityV1 { /** Parameters for the `listApiKeys` operation. */ export interface ListApiKeysParams { - /** Account ID of the API keys(s) to query. If a service IAM ID is specified in iam_id then account_id must - * match the account of the IAM ID. If a user IAM ID is specified in iam_id then then account_id must match the - * account of the Authorization token. + /** Account ID of the API keys to query. If a service IAM ID is specified in iam_id then account_id must match + * the account of the IAM ID. If a user IAM ID is specified in iam_id then then account_id must match the account + * of the Authorization token. */ accountId?: string; - /** IAM ID of the API key(s) to be queried. The IAM ID may be that of a user or a service. For a user IAM ID + /** IAM ID of the API keys to be queried. The IAM ID may be that of a user or a service. For a user IAM ID * iam_id must match the Authorization token. */ iamId?: string; @@ -2127,9 +2292,9 @@ namespace IamIdentityV1 { pagesize?: number; /** Optional Prev or Next page token returned from a previous query execution. Default is start with first page. */ pagetoken?: string; - /** Optional parameter to define the scope of the queried API Keys. Can be 'entity' (default) or 'account'. */ + /** Optional parameter to define the scope of the queried API keys. Can be 'entity' (default) or 'account'. */ scope?: ListApiKeysConstants.Scope | string; - /** Optional parameter to filter the type of the queried API Keys. Can be 'user' or 'serviceid'. */ + /** Optional parameter to filter the type of the queried API keys. Can be 'user' or 'serviceid'. */ type?: ListApiKeysConstants.Type | string; /** Optional sort property, valid values are name, description, created_at and created_by. If specified, the * items are sorted by the value of this property. @@ -2144,12 +2309,12 @@ namespace IamIdentityV1 { /** Constants for the `listApiKeys` operation. */ export namespace ListApiKeysConstants { - /** Optional parameter to define the scope of the queried API Keys. Can be 'entity' (default) or 'account'. */ + /** Optional parameter to define the scope of the queried API keys. Can be 'entity' (default) or 'account'. */ export enum Scope { ENTITY = 'entity', ACCOUNT = 'account', } - /** Optional parameter to filter the type of the queried API Keys. Can be 'user' or 'serviceid'. */ + /** Optional parameter to filter the type of the queried API keys. Can be 'user' or 'serviceid'. */ export enum Type { USER = 'user', SERVICEID = 'serviceid', @@ -2633,7 +2798,7 @@ namespace IamIdentityV1 { */ systemAccessTokenExpirationInSeconds?: string; /** Defines the refresh token expiration in seconds. Valid values: - * * Any whole number between '900' and '2592000' + * * Any whole number between '900' and '259200' * * NOT_SET - To unset account setting and use service default. */ systemRefreshTokenExpirationInSeconds?: string; @@ -2665,6 +2830,37 @@ namespace IamIdentityV1 { } } + /** Parameters for the `getMfaStatus` operation. */ + export interface GetMfaStatusParams { + /** ID of the account. */ + accountId: string; + /** iam_id of the user. This user must be the member of the account. */ + iamId: string; + headers?: OutgoingHttpHeaders; + } + + /** Parameters for the `createMfaReport` operation. */ + export interface CreateMfaReportParams { + /** ID of the account. */ + accountId: string; + /** Optional report type. The supported value is 'mfa_status'. List MFA enrollment status for all the + * identities. + */ + type?: string; + headers?: OutgoingHttpHeaders; + } + + /** Parameters for the `getMfaReport` operation. */ + export interface GetMfaReportParams { + /** ID of the account. */ + accountId: string; + /** Reference for the report to be generated, You can use 'latest' to get the latest report for the given + * account. + */ + reference: string; + headers?: OutgoingHttpHeaders; + } + /** Parameters for the `createReport` operation. */ export interface CreateReportParams { /** ID of the account. */ @@ -2693,6 +2889,15 @@ namespace IamIdentityV1 { * model interfaces ************************/ + /** AccountBasedMfaEnrollment. */ + export interface AccountBasedMfaEnrollment { + security_questions: MfaEnrollmentTypeStatus; + totp: MfaEnrollmentTypeStatus; + verisign: MfaEnrollmentTypeStatus; + /** The enrollment complies to the effective requirement. */ + complies: boolean; + } + /** Response body format for Account Settings REST requests. */ export interface AccountSettingsResponse { /** Context with key properties for problem determination. */ @@ -2750,7 +2955,7 @@ namespace IamIdentityV1 { */ system_access_token_expiration_in_seconds: string; /** Defines the refresh token expiration in seconds. Valid values: - * * Any whole number between '900' and '2592000' + * * Any whole number between '900' and '259200' * * NOT_SET - To unset account setting and use service default. */ system_refresh_token_expiration_in_seconds: string; @@ -2941,6 +3146,55 @@ namespace IamIdentityV1 { last_authn?: string; } + /** IdBasedMfaEnrollment. */ + export interface IdBasedMfaEnrollment { + /** Defines the MFA trait for the account. Valid values: + * * NONE - No MFA trait set + * * TOTP - For all non-federated IBMId users + * * TOTP4ALL - For all users + * * LEVEL1 - Email-based MFA for all users + * * LEVEL2 - TOTP-based MFA for all users + * * LEVEL3 - U2F MFA for all users. + */ + trait_account_default: string; + /** Defines the MFA trait for the account. Valid values: + * * NONE - No MFA trait set + * * TOTP - For all non-federated IBMId users + * * TOTP4ALL - For all users + * * LEVEL1 - Email-based MFA for all users + * * LEVEL2 - TOTP-based MFA for all users + * * LEVEL3 - U2F MFA for all users. + */ + trait_user_specific?: string; + /** Defines the MFA trait for the account. Valid values: + * * NONE - No MFA trait set + * * TOTP - For all non-federated IBMId users + * * TOTP4ALL - For all users + * * LEVEL1 - Email-based MFA for all users + * * LEVEL2 - TOTP-based MFA for all users + * * LEVEL3 - U2F MFA for all users. + */ + trait_effective: string; + /** The enrollment complies to the effective requirement. */ + complies: boolean; + } + + /** MfaEnrollmentTypeStatus. */ + export interface MfaEnrollmentTypeStatus { + /** Describes whether the enrollment type is required. */ + required: boolean; + /** Describes whether the enrollment type is enrolled. */ + enrolled: boolean; + } + + /** MfaEnrollments. */ + export interface MfaEnrollments { + /** currently effective mfa type i.e. id_based_mfa or account_based_mfa. */ + effective_mfa_type: string; + id_based_mfa?: IdBasedMfaEnrollment; + account_based_mfa?: AccountBasedMfaEnrollment; + } + /** ProfileClaimRule. */ export interface ProfileClaimRule { /** the unique identifier of the claim rule. */ @@ -3042,6 +3296,22 @@ namespace IamIdentityV1 { profiles?: EntityActivity[]; } + /** ReportMfaEnrollmentStatus. */ + export interface ReportMfaEnrollmentStatus { + /** IAMid of the user who triggered the report. */ + created_by: string; + /** Unique reference used to generate the report. */ + reference: string; + /** Date time at which report is generated. Date is in ISO format. */ + report_time: string; + /** BSS account id of the user who triggered the report. */ + account_id: string; + /** IMS account id of the user who triggered the report. */ + ims_account_id?: string; + /** List of users. */ + users?: UserReportMfaEnrollmentStatus[]; + } + /** ReportReference. */ export interface ReportReference { /** Reference for the report to be generated. */ @@ -3209,6 +3479,29 @@ namespace IamIdentityV1 { /** Time when the user was last authenticated. */ last_authn?: string; } + + /** UserMfaEnrollments. */ + export interface UserMfaEnrollments { + /** IAMid of the user. */ + iam_id: string; + /** currently effective mfa type i.e. id_based_mfa or account_based_mfa. */ + effective_mfa_type?: string; + id_based_mfa?: IdBasedMfaEnrollment; + account_based_mfa?: AccountBasedMfaEnrollment; + } + + /** UserReportMfaEnrollmentStatus. */ + export interface UserReportMfaEnrollmentStatus { + /** IAMid of the user. */ + iam_id: string; + /** Name of the user. */ + name?: string; + /** Username of the user. */ + username: string; + /** Email of the user. */ + email?: string; + enrollments: MfaEnrollments; + } } export = IamIdentityV1; diff --git a/test/integration/iam-identity.v1.test.js b/test/integration/iam-identity.v1.test.js index cec84eb7..4c7184c3 100644 --- a/test/integration/iam-identity.v1.test.js +++ b/test/integration/iam-identity.v1.test.js @@ -63,6 +63,7 @@ let linkId; let accountSettingsEtag; let reportReference; +let reportReferenceMfa; describe('IamIdentityV1_integration', () => { jest.setTimeout(timeout); @@ -1309,7 +1310,7 @@ describe('IamIdentityV1_integration', () => { sessionInvalidationInSeconds: '7200', maxSessionsPerIdentity: '10', systemAccessTokenExpirationInSeconds: '3600', - systemRefreshTokenExpirationInSeconds: '2592000', + systemRefreshTokenExpirationInSeconds: '259200', }; iamIdentityService @@ -1408,6 +1409,66 @@ describe('IamIdentityV1_integration', () => { status: 404, }); }); + test('createMfaReport()', (done) => { + const params = { + accountId, + type: 'mfa_status', + }; + + iamIdentityService + .createMfaReport(params) + .then((res) => { + expect(res).not.toBeNull(); + expect(res.status).toEqual(202); + + const { result } = res; + expect(result).not.toBeNull(); + reportReferenceMfa = result.reference; + expect(reportReferenceMfa).not.toBeNull(); + done(); + }) + .catch((err) => { + console.warn(err); + done(err); + }); + }); + test('getMfaReportComplete()', async () => { + const params = { + accountId, + reference: reportReferenceMfa, + }; + + for (let i = 0; i < 30; i++) { + const response = await iamIdentityService.getMfaReport(params); + if (response.status !== 204) { + expect(response).not.toBeNull(); + expect(response.created_by).not.toBeNull(); + expect(response.reference).not.toBeNull(); + expect(response.report_duration).not.toBeNull(); + break; + } + await sleep(1); + } + }); + test('getMfaReportNotFound()', async () => { + const params = { + accountId, + reference: 'test123', + }; + + await expect(iamIdentityService.getMfaReport(params)).rejects.toMatchObject({ + status: 404, + }); + }); + test('getMfaStatus()', async () => { + const params = { + accountId, + iamId, + }; + const response = await iamIdentityService.getMfaReport(params); + expect(response).not.toBeNull(); + expect(response.iam_id).not.toBeNull(); + }); function getPageTokenFromURL(urlstring) { let pageToken = null; if (urlstring) { diff --git a/test/unit/iam-identity.v1.test.js b/test/unit/iam-identity.v1.test.js index 5331cf86..ce50d17d 100644 --- a/test/unit/iam-identity.v1.test.js +++ b/test/unit/iam-identity.v1.test.js @@ -1,5 +1,5 @@ /** - * (C) Copyright IBM Corp. 2022. + * (C) Copyright IBM Corp. 2023. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -2918,7 +2918,7 @@ describe('IamIdentityV1', () => { const sessionInvalidationInSeconds = '7200'; const maxSessionsPerIdentity = 'testString'; const systemAccessTokenExpirationInSeconds = '3600'; - const systemRefreshTokenExpirationInSeconds = '2592000'; + const systemRefreshTokenExpirationInSeconds = '259200'; const updateAccountSettingsParams = { ifMatch, accountId, @@ -3022,6 +3022,271 @@ describe('IamIdentityV1', () => { }); }); + describe('getMfaStatus', () => { + describe('positive tests', () => { + function __getMfaStatusTest() { + // Construct the params object for operation getMfaStatus + const accountId = 'testString'; + const iamId = 'testString'; + const getMfaStatusParams = { + accountId, + iamId, + }; + + const getMfaStatusResult = iamIdentityService.getMfaStatus(getMfaStatusParams); + + // all methods should return a Promise + expectToBePromise(getMfaStatusResult); + + // assert that create request was called + expect(createRequestMock).toHaveBeenCalledTimes(1); + + const mockRequestOptions = getOptions(createRequestMock); + + checkUrlAndMethod(mockRequestOptions, '/v1/mfa/accounts/{account_id}/status', 'GET'); + const expectedAccept = 'application/json'; + const expectedContentType = undefined; + checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); + expect(mockRequestOptions.qs.iam_id).toEqual(iamId); + expect(mockRequestOptions.path.account_id).toEqual(accountId); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __getMfaStatusTest(); + + // enable retries and test again + createRequestMock.mockClear(); + iamIdentityService.enableRetries(); + __getMfaStatusTest(); + + // disable retries and test again + createRequestMock.mockClear(); + iamIdentityService.disableRetries(); + __getMfaStatusTest(); + }); + + test('should prioritize user-given headers', () => { + // parameters + const accountId = 'testString'; + const iamId = 'testString'; + const userAccept = 'fake/accept'; + const userContentType = 'fake/contentType'; + const getMfaStatusParams = { + accountId, + iamId, + headers: { + Accept: userAccept, + 'Content-Type': userContentType, + }, + }; + + iamIdentityService.getMfaStatus(getMfaStatusParams); + checkMediaHeaders(createRequestMock, userAccept, userContentType); + }); + }); + + describe('negative tests', () => { + test('should enforce required parameters', async () => { + let err; + try { + await iamIdentityService.getMfaStatus({}); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + + test('should reject promise when required params are not given', async () => { + let err; + try { + await iamIdentityService.getMfaStatus(); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + }); + }); + + describe('createMfaReport', () => { + describe('positive tests', () => { + function __createMfaReportTest() { + // Construct the params object for operation createMfaReport + const accountId = 'testString'; + const type = 'testString'; + const createMfaReportParams = { + accountId, + type, + }; + + const createMfaReportResult = iamIdentityService.createMfaReport(createMfaReportParams); + + // all methods should return a Promise + expectToBePromise(createMfaReportResult); + + // assert that create request was called + expect(createRequestMock).toHaveBeenCalledTimes(1); + + const mockRequestOptions = getOptions(createRequestMock); + + checkUrlAndMethod(mockRequestOptions, '/v1/mfa/accounts/{account_id}/report', 'POST'); + const expectedAccept = 'application/json'; + const expectedContentType = undefined; + checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); + expect(mockRequestOptions.qs.type).toEqual(type); + expect(mockRequestOptions.path.account_id).toEqual(accountId); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __createMfaReportTest(); + + // enable retries and test again + createRequestMock.mockClear(); + iamIdentityService.enableRetries(); + __createMfaReportTest(); + + // disable retries and test again + createRequestMock.mockClear(); + iamIdentityService.disableRetries(); + __createMfaReportTest(); + }); + + test('should prioritize user-given headers', () => { + // parameters + const accountId = 'testString'; + const userAccept = 'fake/accept'; + const userContentType = 'fake/contentType'; + const createMfaReportParams = { + accountId, + headers: { + Accept: userAccept, + 'Content-Type': userContentType, + }, + }; + + iamIdentityService.createMfaReport(createMfaReportParams); + checkMediaHeaders(createRequestMock, userAccept, userContentType); + }); + }); + + describe('negative tests', () => { + test('should enforce required parameters', async () => { + let err; + try { + await iamIdentityService.createMfaReport({}); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + + test('should reject promise when required params are not given', async () => { + let err; + try { + await iamIdentityService.createMfaReport(); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + }); + }); + + describe('getMfaReport', () => { + describe('positive tests', () => { + function __getMfaReportTest() { + // Construct the params object for operation getMfaReport + const accountId = 'testString'; + const reference = 'testString'; + const getMfaReportParams = { + accountId, + reference, + }; + + const getMfaReportResult = iamIdentityService.getMfaReport(getMfaReportParams); + + // all methods should return a Promise + expectToBePromise(getMfaReportResult); + + // assert that create request was called + expect(createRequestMock).toHaveBeenCalledTimes(1); + + const mockRequestOptions = getOptions(createRequestMock); + + checkUrlAndMethod(mockRequestOptions, '/v1/mfa/accounts/{account_id}/report/{reference}', 'GET'); + const expectedAccept = 'application/json'; + const expectedContentType = undefined; + checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); + expect(mockRequestOptions.path.account_id).toEqual(accountId); + expect(mockRequestOptions.path.reference).toEqual(reference); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __getMfaReportTest(); + + // enable retries and test again + createRequestMock.mockClear(); + iamIdentityService.enableRetries(); + __getMfaReportTest(); + + // disable retries and test again + createRequestMock.mockClear(); + iamIdentityService.disableRetries(); + __getMfaReportTest(); + }); + + test('should prioritize user-given headers', () => { + // parameters + const accountId = 'testString'; + const reference = 'testString'; + const userAccept = 'fake/accept'; + const userContentType = 'fake/contentType'; + const getMfaReportParams = { + accountId, + reference, + headers: { + Accept: userAccept, + 'Content-Type': userContentType, + }, + }; + + iamIdentityService.getMfaReport(getMfaReportParams); + checkMediaHeaders(createRequestMock, userAccept, userContentType); + }); + }); + + describe('negative tests', () => { + test('should enforce required parameters', async () => { + let err; + try { + await iamIdentityService.getMfaReport({}); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + + test('should reject promise when required params are not given', async () => { + let err; + try { + await iamIdentityService.getMfaReport(); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + }); + }); + describe('createReport', () => { describe('positive tests', () => { function __createReportTest() { @@ -3051,7 +3316,7 @@ describe('IamIdentityV1', () => { checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); expect(mockRequestOptions.qs.type).toEqual(type); expect(mockRequestOptions.qs.duration).toEqual(duration); - expect(mockRequestOptions.path['account_id']).toEqual(accountId); + expect(mockRequestOptions.path.account_id).toEqual(accountId); } test('should pass the right params to createRequest with enable and disable retries', () => { @@ -3137,7 +3402,7 @@ describe('IamIdentityV1', () => { const expectedAccept = 'application/json'; const expectedContentType = undefined; checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); - expect(mockRequestOptions.path['account_id']).toEqual(accountId); + expect(mockRequestOptions.path.account_id).toEqual(accountId); expect(mockRequestOptions.path.reference).toEqual(reference); }