From 83674446fab72f353ef7c284c1fd2461c1d2bb14 Mon Sep 17 00:00:00 2001 From: Sai Saran Vaidyanathan Date: Thu, 7 Dec 2023 10:13:58 -0800 Subject: [PATCH] feat: add test case for #404 --- .../apiproxy/BN001-xsd-resources.xml | 10 + .../policies/AM-CleanResponseHeaders.xml | 5 + .../policies/AM-InjectProxyVersionHeader.xml | 7 + .../apiproxy/policies/AM-Response-1.xml | 24 + .../apiproxy/policies/JS-1.xml | 16 + .../apiproxy/policies/MV-1.xml | 4 + .../apiproxy/policies/RF-UnknownRequest.xml | 16 + .../apiproxy/proxies/endpoint1.xml | 75 + .../apiproxy/resources/invalid_file.js | 0 .../apiproxy/resources/xsd/DomainData.xsd | 1519 +++++++++++++++++ .../apiproxy/resources/xsd/GlobalData.xsd | 211 +++ .../apiproxy/resources/xsd/ProductService.xsd | 44 + test/specs/BN001-incorrectResourceTest.js | 60 + 13 files changed, 1991 insertions(+) create mode 100644 test/fixtures/resources/BN001-incorrect-resources/apiproxy/BN001-xsd-resources.xml create mode 100644 test/fixtures/resources/BN001-incorrect-resources/apiproxy/policies/AM-CleanResponseHeaders.xml create mode 100644 test/fixtures/resources/BN001-incorrect-resources/apiproxy/policies/AM-InjectProxyVersionHeader.xml create mode 100644 test/fixtures/resources/BN001-incorrect-resources/apiproxy/policies/AM-Response-1.xml create mode 100644 test/fixtures/resources/BN001-incorrect-resources/apiproxy/policies/JS-1.xml create mode 100644 test/fixtures/resources/BN001-incorrect-resources/apiproxy/policies/MV-1.xml create mode 100644 test/fixtures/resources/BN001-incorrect-resources/apiproxy/policies/RF-UnknownRequest.xml create mode 100644 test/fixtures/resources/BN001-incorrect-resources/apiproxy/proxies/endpoint1.xml create mode 100644 test/fixtures/resources/BN001-incorrect-resources/apiproxy/resources/invalid_file.js create mode 100644 test/fixtures/resources/BN001-incorrect-resources/apiproxy/resources/xsd/DomainData.xsd create mode 100644 test/fixtures/resources/BN001-incorrect-resources/apiproxy/resources/xsd/GlobalData.xsd create mode 100644 test/fixtures/resources/BN001-incorrect-resources/apiproxy/resources/xsd/ProductService.xsd create mode 100644 test/specs/BN001-incorrectResourceTest.js diff --git a/test/fixtures/resources/BN001-incorrect-resources/apiproxy/BN001-xsd-resources.xml b/test/fixtures/resources/BN001-incorrect-resources/apiproxy/BN001-xsd-resources.xml new file mode 100644 index 00000000..49dcaf7e --- /dev/null +++ b/test/fixtures/resources/BN001-incorrect-resources/apiproxy/BN001-xsd-resources.xml @@ -0,0 +1,10 @@ + + + 1489339923158 + dino + + BN001-xsd-resources + 1489340418969 + orgAdmin + + diff --git a/test/fixtures/resources/BN001-incorrect-resources/apiproxy/policies/AM-CleanResponseHeaders.xml b/test/fixtures/resources/BN001-incorrect-resources/apiproxy/policies/AM-CleanResponseHeaders.xml new file mode 100644 index 00000000..8d3e8e4e --- /dev/null +++ b/test/fixtures/resources/BN001-incorrect-resources/apiproxy/policies/AM-CleanResponseHeaders.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/test/fixtures/resources/BN001-incorrect-resources/apiproxy/policies/AM-InjectProxyVersionHeader.xml b/test/fixtures/resources/BN001-incorrect-resources/apiproxy/policies/AM-InjectProxyVersionHeader.xml new file mode 100644 index 00000000..9e346d89 --- /dev/null +++ b/test/fixtures/resources/BN001-incorrect-resources/apiproxy/policies/AM-InjectProxyVersionHeader.xml @@ -0,0 +1,7 @@ + + + +
{apiproxy.name} r{apiproxy.revision}
+
+
+
diff --git a/test/fixtures/resources/BN001-incorrect-resources/apiproxy/policies/AM-Response-1.xml b/test/fixtures/resources/BN001-incorrect-resources/apiproxy/policies/AM-Response-1.xml new file mode 100644 index 00000000..7d6e07df --- /dev/null +++ b/test/fixtures/resources/BN001-incorrect-resources/apiproxy/policies/AM-Response-1.xml @@ -0,0 +1,24 @@ + + + + t + + + + + d + + + + true + + { + "status" : "ok", + "time" : "{t}", + "date" : "{d}" +} + OK + 200 + + response + diff --git a/test/fixtures/resources/BN001-incorrect-resources/apiproxy/policies/JS-1.xml b/test/fixtures/resources/BN001-incorrect-resources/apiproxy/policies/JS-1.xml new file mode 100644 index 00000000..14980bd2 --- /dev/null +++ b/test/fixtures/resources/BN001-incorrect-resources/apiproxy/policies/JS-1.xml @@ -0,0 +1,16 @@ + + + function getProp(setname, shortpropname) { + try { + var name = 'propertyset.' + setname + '.' + shortpropname; + var c = String(context.getVariable(name)); + return c; + } + catch (e) { + return String(e); + } + } + var keys = ['value1','value2','bailiwick','identifier'] + keys.forEach(function(k) {getProp('set1',k);}); + + diff --git a/test/fixtures/resources/BN001-incorrect-resources/apiproxy/policies/MV-1.xml b/test/fixtures/resources/BN001-incorrect-resources/apiproxy/policies/MV-1.xml new file mode 100644 index 00000000..39905ccf --- /dev/null +++ b/test/fixtures/resources/BN001-incorrect-resources/apiproxy/policies/MV-1.xml @@ -0,0 +1,4 @@ + + message + xsd://ProduceService.xsd + diff --git a/test/fixtures/resources/BN001-incorrect-resources/apiproxy/policies/RF-UnknownRequest.xml b/test/fixtures/resources/BN001-incorrect-resources/apiproxy/policies/RF-UnknownRequest.xml new file mode 100644 index 00000000..c92bcb3f --- /dev/null +++ b/test/fixtures/resources/BN001-incorrect-resources/apiproxy/policies/RF-UnknownRequest.xml @@ -0,0 +1,16 @@ + + true + + + { + "error" : { + "code" : 404.01, + "message" : "that request was unknown; try a different request." + } +} + + 404 + Not Found + + + diff --git a/test/fixtures/resources/BN001-incorrect-resources/apiproxy/proxies/endpoint1.xml b/test/fixtures/resources/BN001-incorrect-resources/apiproxy/proxies/endpoint1.xml new file mode 100644 index 00000000..6d83e219 --- /dev/null +++ b/test/fixtures/resources/BN001-incorrect-resources/apiproxy/proxies/endpoint1.xml @@ -0,0 +1,75 @@ + + Proxy Endpoint 1 + + /BN001-propertiesset-demo1 + + secure + + + + + + AM-InjectProxyVersionHeader + + true + + + + + + JS-1 + + + + + AM-CleanResponseHeaders + + + + + + + + + AM-InjectProxyVersionHeader + + + + + + + + + + + + + + + + MV-1 + + + + + AM-Response-1 + + + (proxy.pathsuffix MatchesPath "/t1") and (request.verb = "POST") + + + + + + RF-UnknownRequest + + + + + + + + + + + diff --git a/test/fixtures/resources/BN001-incorrect-resources/apiproxy/resources/invalid_file.js b/test/fixtures/resources/BN001-incorrect-resources/apiproxy/resources/invalid_file.js new file mode 100644 index 00000000..e69de29b diff --git a/test/fixtures/resources/BN001-incorrect-resources/apiproxy/resources/xsd/DomainData.xsd b/test/fixtures/resources/BN001-incorrect-resources/apiproxy/resources/xsd/DomainData.xsd new file mode 100644 index 00000000..e2072b89 --- /dev/null +++ b/test/fixtures/resources/BN001-incorrect-resources/apiproxy/resources/xsd/DomainData.xsd @@ -0,0 +1,1519 @@ + + + + valid values for PaymentTypeDS + + + + + + + + + + + + + + + + + + + + + + + + + Valid values for PaymentTypeCD + + + + + + + + + + + + + valid values for AddressPurpose. BILLING is only value currently returned + + + + + + + + + + + + + + + + + + + + + + + + + + valid values for lineofBusinessCD + + + + + + + + + + + valid values for lineOfBusinessDS + + + + + + + + + + + valid values for AddressUsage + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Valid values for PaymentHierarchyTypeCD + + + + + + + + + + + + + + + + + + + + + Contains the attributes applicable to the Account + + + + + + + + the language code of the account, G* native value + + + + + + language code of the account in ISO format + + + + + + indicates whether spend on the account earns CashBack + + + + + + + +

Statement flag.

+

Space | normal statement

+

O | online only

+

H | Hold

+

R | Returned

+

S | Signed out

+

I | Interim

+

C | Cycle

+

U | User defined

+

Z | Suppressed

+

0-9 | User hold codes

+

P | Paperless code to be archived but not printed (NEW)

+ +

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

]]> +
+
+
+ + + Indicates the paperless statement status of the account. + + + + + + + Indicates if Account has DPP balalnce + + + +
+
+ + + + + Three character ISO standard country code]]> + + + + + + + + + + + + + Indicates the type of telephone number being returned + + + + + + + + + + + + + current cardnumber belonging to the Card on the account + + + + + + indicates whether the card is basic or supplementary + + + + + + Date since Card opened + + + + + + + + + + + + + + + + + Currency in standard ISO format + + + + + + ISO standard currency code]]> + + + + + + Number of decimal places for the market currency. + + + + + + + + + + + + + + + + + + + + + + so here should we associate to the generic CountryType ? I would say yes, if the field is returning real standard country data + + + + + + + + + + Indicates the type of address being returned. + + + + + + + + + + + + + + + + Line of Business for the account + + + + + + + + + LOB code value +

+

]]> +
+
+
+ + + LOB description + + + +
+
+ + + This parameter represents the direct debit information on a card account. + + + + + + + + + + + Valid values: 'A' , 'J', 'M'

+

'A' - Fixed Amount Payment

+

'J' - Full Payment

+

'M' - Minimum 5% Payment

+

]]> +
+
+
+ + + + + + + + + + + + Valid values: '0', '1', '2', '3', '4'

+

'0' - DD not used

+

'1' - DD Monthly

+

'2' - DD Weekly

+

'3' - DD Bi-weekly

+

'4' - DD Daily

+

]]> +
+
+
+ + + + + + +
+
+ + + This parameter type represents the sub-entity that is defined by a collection of base balance summary data. + + + + + + ISO 3-Alpha currency code that identifies the unit of currency. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Valid values: '0', '3'

+

'0' - Non Direct Debit Card Member

+

'3' - Direct Debit Card Member

+

]]> +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + See parameter type 'DirectDebitBalanceSummaryType'. + + + +
+
+ + + + + + + + + + Valid values for Address line No + + + + + + + + + + + + + + + + + + + + This parameter type represents the sub-entity that is defined by a collection of card level balance summary data. + + + + + + + 15-digit card number | basic and supp.

+

It will be left justified with trailing spaces to make the length 19, as defined by ISO.

+

]]> +
+
+
+ + +
+
+ + + status of a Card on an Account. NOT CURRENTLY AVAILABLE + + + + + + placeholder for future release, not currently available + + + + + + placeholder for future release, not currently available + + + + + + palceholder for future release, not currently available + + + + + + palceholder for future release, not currently available + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + indicates the lift date for alternate customer record + + + + + + + + + + + + + + container to hold the AccountDemographic fragment for the Account + + + + + + + + + + + + + + + + + + + + + + + + 1 = Highest priority + + + + + + + + + Product info at account level. + + + + + + Globestar PCT for the Account (Basic Card) + + + + + + G* LOGO + + + + + + + PaymentType, also referred to as card Type - Charge, revolve, Loan etc + + + + + + PaymentType description + + + + + + + + Plastic colour, also referred to as Short Description

+

+

]]> +
+
+
+ + + digial asset ID of the account (basic card). used to identify the correct card art + + + + + + + +
+
+ + + + + + + + + + + + + + + + + 0 = the most recent statement cycle

+

(assuming the cycle data ordered when returned from G* tbd)

+

]]> +
+
+
+
+ + + This parameter type represents the Account Balance Summary entity which encompasses a number of sub-entities: Base Balance Summary, Card Balance Summary, Plan Balance Summary and Loan Plan Balance Summary. + + + + + + 15-digit card number specified to locate the card account, which identifies the card account from customer's perspective.It will be left justified with trailing spaces to make the length 19, as defined by ISO. + + + + + + This represents cycle cut date. Value = '0001-01-01' represents the current un-billed cycle. Else, the actual cycle cut date. + + + + + + See parameter type 'CardBalanceSummaryType'. + + + + + + See parameter type 'PlanBalanceSummaryType'. + + + + + + See parameter type 'BaseBalanceSummaryType'. + + + + + + Number of Supplementary Cards + + + + + + + + + + + + + indicates whether Payflex applies for the account +

]]> +
+
+
+ + + ]]> + + + +
+
+ + + This parameter type represents the plan information on a card account. + + + + + + + Globestar's valid values: 'C', 'A', 'L', 'T', 'B', other

+

"C', 'A' = Cash

+

'L' = Loan

+

'T', 'B' = Balance, Transfers

+

other = Retail"

+

Will be mapped to enumeration literals:

+

CASH, LOAN, BT, RETAIL

+

+

]]> +
+
+
+ + + + + + + + + + Globestar's valid values: 'M', 'Y'

+

'M' = Monthly

+

'Y' = Yearly

+

Will be mapped to enumeration literals:

+

M, Y

+

]]> +
+
+
+ + + + + + + + + + + + +
+
+ + + + + + + See parameter type 'DirectDebitInfoType'. + + + + + + + + Provides the information pertaining to the Account Status + + + + + + populated when account is cancelled. returns G* block code 1 value + + + + + + block code 1 description + + + + + + date the block code was applied + + + + + + account status info for the account, may be present for cancelled or non-cancelled accounts. G* block code 2 value + + + + + + G* block code 2 description + + + + + + date the block code 2 was applied + + + + + + + + market is an internal USex concept. Markets are associated to Countries, however one Country may have multiple markets. G* ORG + + + + + + Globestar ORG Number]]> + + + + + + + + + + This parameter type represents the sub-entity that is defined by a collection of plan level balance summary data. + + + + + + + + + + + + +

This field is ONLY available to Japan or Canada.

+

For Japan the Principal Minimum Due is stored in this field.

+

For Canada the Finance Charge is stored in this field.

+ +

+

]]> +
+
+
+ + + + + + + + + + + + + + + + + + Valid values:

+

space - Not used (not a deferred plan)

+

'1 - Paid'

+

'2 - Due'

+

'3 - Deferred'

+

]]> +
+
+
+ + + See parameter type 'LoanPlanBalanceSummaryType'. + + + + + + See parameter type 'PlanInfoType'. + + + +
+
+ + + + + + + + + + + information specific to a given plastic + + + + + + cardnumber specific to the plastic in question + + + + + + Indicates whether this plastic is the current card. G* return values Y or N. This will be converted to Boolean 1, 0]]> + + + + + + Need to verify if this can really be returned as DataType or if it needs to be string]]> + + + + + + Need to verify if this can really be returned as DataType or if it needs to be string]]> + + + + + + The name embossed on the plastic]]> + + + + + + + + Additional name to be embossed on the second + + For example, this field may contain the name of a business if the card is issued for a business account. +

+

+ G* GetARCustomer field : OneCardInfor / . G* data field + AMED-EMBOSSED-NAME-2 +

+

+ Added per MYCA CardService requirements +

+

+ +

]]> +
+
+
+ + + plastic level block code + + + + + + + date the block code was applied + + + +
+
+ + + Product info specific to a given card on an Account + + + + + + current cardnumber of the Card + + + + + + indicates whether the card belongs to basic or supplementary + + + + + + G* PCT for the Card (supp PCT may differ from the basic/Account level PCT) + + + + + + digital asset ID for the card + + + + + + product short description (family/colour) for the card. May differ from that of the Basic (Account) + + + + + + + + Product info at account level. + + + + + + + + + + + G* LOGO + + + + + + Globestar PCT + + + + + + PaymentType, also referred to as card Type - Charge, revolve, Loan etc + + + + + + PaymentType description + + + + + + + Plastic colour, also referred to as Short Description

+

+

]]> +
+
+
+ + + + digial asset ID of the account (basic card). used to identify the correct card art + + + + + + + Payment Application Method PH1 description + + + + + + Payment Application Method PH2 description + + + + +
+ + + The card number in the service request for identifying the card account. + + + +
+ + + + + + + + + + + + current cardnumber belonging to the cardmember + + + + + + Indicates whether this is Basic or Supplementary cardmember + + + + + + National ID of cardmember. + + + + + + national ID 2 applies only to Basic + + + + + + Birth date of cardmember + + + + + + . Values are M, F, U]]> + + + + + + cardmember since date of cardmember + + + + + + first name of cardmember + + + + + + middle name of cardmember + + + + + + last name of cardmember + + + + + + second last name of cardmember + + + + + + Cm Title description of cardmemberProvided by AMNA-TITLE when a BASIC, AMED-GFS-TITLE when a SUPP + + + + + + business name + + + + + + + + + ]]> + + + + + + ]]> + + + + + + + + + + this is the transformed age value : needs enum. valid values are 0, 30, 60, 90, 120. NOT RETURNED AT PRESENT + + + + + + this field is the age code value held on G* + + + + + + + + This parameter type represents the sub-entity that is defined by a collection of loan plan balance summary data. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Sum of Principal + Int + Ins + Fees outstanding on Loans

+ +

]]> +
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/test/fixtures/resources/BN001-incorrect-resources/apiproxy/resources/xsd/GlobalData.xsd b/test/fixtures/resources/BN001-incorrect-resources/apiproxy/resources/xsd/GlobalData.xsd new file mode 100644 index 00000000..3ffc5be8 --- /dev/null +++ b/test/fixtures/resources/BN001-incorrect-resources/apiproxy/resources/xsd/GlobalData.xsd @@ -0,0 +1,211 @@ + + + Description = This schema defines Types and Elements globally applicable to all iSL services. MajorVersion = 1 MinorVersion = 0 -------------------------------------------------------------------------------------------- Revision History -------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------- Date | Version | Description | Author | Contributor(s) -------------------------------------------------------------------------------------------- Jan 2011 1.0 Initial Chris Example Rakesh Example -------------------------------------------------------------------------------------------- + + + + <p>This parameter type conveys the error details.</p> + + + + + + <p>See parameter type 'RootCausesType'.</p> + + + + + + + + <p>This parameter type conveys error details provide by the back-end platforms.</p> + + + + + + <p>See parameter type 'PaltformErrorType'.</p> + + + + + + + + <p>The parameter type represents the error details provided by the back-end platforms</p> + + + + + + + + + + + + + + + <p>Unique consumer identifier to be provided by consumer per service request and used for end to end tracing.</p> + + + + + + + + + + + + <p>This indicates the end user who initiates the business function.</p> + + + + + + + + + <p>The parameter type represents the result of the service operation, whether successful or failed.</p> + + + + + + + + + + <p>This parameter type conveys the error details associated with application errors or system errors.</p> + + + + + + <p>See parameter type 'ErrorType'.</p> + + + + + + <p>See parameter type 'ErrorType'.</p> + + + + + + + + + <p>This message type represents the data elements common in all service request messages for consuming all service operations.</p> + + + + + + <p>This message type represents the data elements common in all service response messages returned by all service operations.</p> + + + + + + <p>See parameter type 'ErrorResponseType'.</p><p></p> + + + + + + <p>See parameter type 'ResponseStatusType'.</p> + + + + + + + + + <p>This message type conveys the information about an error occurred during the execution of a service operation.</p> + + + + + + + + + + + <p>Unique consumer identifier to be provided by consumer per service request and used for end to end tracing.</p> + + + + + + + + + + + + <p>Unique consumer identifier to be provided by consumer per service request and used for end to end tracing.</p> + + + + + + + + + + + + + + + + + + + <p>Code to indicate success</p> + + + + + + <p>Code to indicate failure</p> + + + + + + <p>Code to indicate partial response</p> + + + + + + + + + + <p></p> + + + + + + <p></p> + + + + + + + diff --git a/test/fixtures/resources/BN001-incorrect-resources/apiproxy/resources/xsd/ProductService.xsd b/test/fixtures/resources/BN001-incorrect-resources/apiproxy/resources/xsd/ProductService.xsd new file mode 100644 index 00000000..07ef55eb --- /dev/null +++ b/test/fixtures/resources/BN001-incorrect-resources/apiproxy/resources/xsd/ProductService.xsd @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/specs/BN001-incorrectResourceTest.js b/test/specs/BN001-incorrectResourceTest.js new file mode 100644 index 00000000..5db7d528 --- /dev/null +++ b/test/specs/BN001-incorrectResourceTest.js @@ -0,0 +1,60 @@ +/* + Copyright 2019-2023 Google LLC + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + https://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +/* jshint esversion:9, node:true, strict:implied */ +/* global describe, it */ + +const assert = require("assert"), + path = require("path"), + debug = require("debug")("apigeelint:BN001-test"), + bl = require("../../lib/package/bundleLinter.js"); + +describe(`BN001 - bundle with incorrect resource`, () => { + it('should generate the expected errors', () => { + const configuration = { + debug: true, + source: { + type: "filesystem", + path: path.resolve(__dirname, '../fixtures/resources/BN001-incorrect-resources/apiproxy'), + bundleType: "apiproxy" + }, + profile: 'apigee', + excluded: {}, + setExitCode: false, + output: () => {} // suppress output + }; + + bl.lint(configuration, (bundle) => { + const items = bundle.getReport(); + assert.ok(items); + assert.ok(items.length); + const actualErrors = items.filter(item => item.messages && item.messages.length); + console.log("**actualErrors: "+ JSON.stringify(actualErrors)); + debug(JSON.stringify(actualErrors, null, 1)); + + assert.equal(actualErrors.length, 1); + assert.ok(actualErrors[0].messages.length); + assert.equal(actualErrors[0].messages.length, 1); + assert.ok(actualErrors[0].messages[0].message); + assert.ok(actualErrors[0].messages[0].message.startsWith('Unexpected extension found with file'), + actualErrors[0].messages[0].message); + assert.ok(actualErrors[0].messages[0].message.indexOf("invalid_file.js") > 0, + actualErrors[0].messages[0].message); + + }); + }); + +});