Skip to content

Commit

Permalink
FIRECERT-2274-errorschema fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Nandana-NNR committed Aug 22, 2024
1 parent 8019d2b commit 512eb92
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 70 deletions.
4 changes: 2 additions & 2 deletions src/EventInvocation.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export class EventInvocation {
let schemaValidationResult = {};
let schemaValidationStatus = CONSTANTS.PASS;
if (message.params.isNotSupportedApi == true) {
schemaValidationResult = errorSchemaCheck(listenerResponse, process.env.COMMUNICATION_MODE);
schemaValidationResult = errorSchemaCheck(listenerResponse);
schemaValidationStatus = CONSTANTS.FAIL;
}
registrationResponse['eventListenerSchemaResult'] = {
Expand All @@ -153,7 +153,7 @@ export class EventInvocation {
}
registrationResponse['eventListenerResponse'] = { result: null, error: listenerResponse };
// In case of error, validate error against errorschema
const schemaValidationResult = errorSchemaCheck(listenerResponse, process.env.COMMUNICATION_MODE);
const schemaValidationResult = errorSchemaCheck(listenerResponse);
if (schemaValidationResult && schemaValidationResult.errors && schemaValidationResult.errors.length > 0) {
registrationResponse['eventListenerSchemaResult'] = {
status: CONSTANTS.FAIL,
Expand Down
4 changes: 2 additions & 2 deletions src/MethodInvoker.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export class MethodInvoker {
if (process.env.STANDALONE == true) {
// if the method is not supported and it gives a valid response, validate against errorschema instead of api schema
if (message.params.isNotSupportedApi == true && response != undefined) {
schemaValidationResult = errorSchemaCheck(response, process.env.COMMUNICATION_MODE);
schemaValidationResult = errorSchemaCheck(response);
}
}
} catch (error) {
Expand Down Expand Up @@ -135,7 +135,7 @@ export class MethodInvoker {
let apiResponse, responseCode, schemaValidationStatus;
if (err) {
apiResponse = { result: null, error: err };
schemaValidationResult = errorSchemaCheck(err, process.env.COMMUNICATION_MODE);
schemaValidationResult = errorSchemaCheck(err);
if (schemaValidationResult && schemaValidationResult.errors && schemaValidationResult.errors.length > 0) {
if (err.message != undefined && CONSTANTS.ERROR_LIST.includes(err.message)) {
responseCode = CONSTANTS.STATUS_CODE[3];
Expand Down
12 changes: 6 additions & 6 deletions src/Test_Runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const TAG = '[Test_Runner]: ';
*/
let execMode;
let invokedSdk;
let errorSchemaBasedOnMode;
let errorSchemaValue;

/*
Start and End time of API invocation
Expand Down Expand Up @@ -103,7 +103,7 @@ export class Test_Runner {
const resultStartTime = new Date();
let suiteStartTime = new Date();
let errorSchemaResult;
errorSchemaBasedOnMode = process.env.COMMUNICATION_MODE == CONSTANTS.TRANSPORT ? errorSchema[CONSTANTS.ERROR_SCHEMA_TRANSPORT] : errorSchema[CONSTANTS.ERROR_SCHEMA_SDK];
errorSchemaValue = errorSchema[errorSchema];

// This is the list of validation Results for each api ,This is the list that will be used for creating the report
for (const executionMode of execModes) {
Expand Down Expand Up @@ -200,9 +200,9 @@ export class Test_Runner {
}
if (this.methodFilters.isExceptionMethod(methodObj.name, example.params)) {
if (method.examples[exampleIndex].schema) {
method.examples[exampleIndex].schema = errorSchemaBasedOnMode;
method.examples[exampleIndex].schema = errorSchemaValue;
} else {
method.result.schema = errorSchemaBasedOnMode;
method.result.schema = errorSchemaValue;
}
}
if (communicationMode == CONSTANTS.TRANSPORT) {
Expand Down Expand Up @@ -1206,15 +1206,15 @@ export class Test_Runner {
let obj;
const NOT_SUPPORTED_ERROR_MESSAGES = ['Unsupported', 'Not supported', 'not supported'];
const errMessage = '{"code":' + error.code + ',"message":' + error.message + '}';
const schemaValidationResult = errorSchemaCheck(error, process.env.COMMUNICATION_MODE);
const schemaValidationResult = errorSchemaCheck(error);
if (schemaValidationResult && schemaValidationResult.errors && schemaValidationResult.errors.length > 0) {
obj = {
error: error,
param: example.params,
errorSchemaResult: true,
methodWithExampleName: methodWithExampleName,
methodUuid: this.createUUID(),
schemaData: errorSchemaBasedOnMode,
schemaData: errorSchemaValue,
};
} else {
NOT_SUPPORTED_ERROR_MESSAGES.some((errorMessage) => error.message.includes(errorMessage));
Expand Down
2 changes: 0 additions & 2 deletions src/constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,4 @@ export const CONSTANTS = {
EXCLUDED_METHODS_FOR_MFOS: [],
...CONFIG_CONSTANTS,
VERSIONS: 'Versions',
ERROR_SCHEMA_TRANSPORT: 'errorSchemaTransport',
ERROR_SCHEMA_SDK: 'errorSchemaSDK',
};
76 changes: 21 additions & 55 deletions src/source/errorSchema.json
Original file line number Diff line number Diff line change
@@ -1,57 +1,23 @@
{
"errorSchemaSDK": {
"oneOf": [
{
"type": "object",
"additionalProperties": false,
"required": [
"code",
"message"
],
"properties": {
"code": {
"title": "errorObjectCode",
"description": "A Number that indicates the error type that occurred. This MUST be an integer. The error codes from and including -32768 to -32000 are reserved for pre-defined errors. These pre-defined errors SHOULD be assumed to be returned from any JSON-RPC api.",
"type": "integer"
},
"message": {
"title": "errorObjectMessage",
"description": "A String providing a short description of the error. The message SHOULD be limited to a concise single sentence.",
"type": "string"
},
"data": {
"title": "errorObjectData",
"description": "A Primitive or Structured value that contains additional information about the error. This may be omitted. The value of this member is defined by the Server (e.g. detailed error information, nested errors etc.)."
}
}
},
{
"type": "string"
}
]
},
"errorSchemaTransport": {
"type": "object",
"additionalProperties": false,
"required": [
"code",
"message"
],
"properties": {
"code": {
"title": "errorObjectCode",
"description": "A Number that indicates the error type that occurred. This MUST be an integer. The error codes from and including -32768 to -32000 are reserved for pre-defined errors. These pre-defined errors SHOULD be assumed to be returned from any JSON-RPC api.",
"type": "integer"
},
"message": {
"title": "errorObjectMessage",
"description": "A String providing a short description of the error. The message SHOULD be limited to a concise single sentence.",
"type": "string"
},
"data": {
"title": "errorObjectData",
"description": "A Primitive or Structured value that contains additional information about the error. This may be omitted. The value of this member is defined by the Server (e.g. detailed error information, nested errors etc.)."
}
}
"errorSchema": {
"type": "object",
"additionalProperties": false,
"required": ["code", "message"],
"properties": {
"code": {
"title": "errorObjectCode",
"description": "A Number that indicates the error type that occurred. This MUST be an integer. The error codes from and including -32768 to -32000 are reserved for pre-defined errors. These pre-defined errors SHOULD be assumed to be returned from any JSON-RPC api.",
"type": "integer"
},
"message": {
"title": "errorObjectMessage",
"description": "A String providing a short description of the error. The message SHOULD be limited to a concise single sentence.",
"type": "string"
},
"data": {
"title": "errorObjectData",
"description": "A Primitive or Structured value that contains additional information about the error. This may be omitted. The value of this member is defined by the Server (e.g. detailed error information, nested errors etc.)."
}
}
}
}
}
5 changes: 2 additions & 3 deletions src/utils/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,10 @@ function filterExamples(programlist, programType, offeringType) {
return offeringList;
}

function errorSchemaCheck(err, communicationMode) {
function errorSchemaCheck(err) {
let schemaValidationResult;
if (errorSchema) {
const errorSchemaBasedOnMode = communicationMode == CONSTANTS.TRANSPORT ? errorSchema[CONSTANTS.ERROR_SCHEMA_TRANSPORT] : errorSchema[CONSTANTS.ERROR_SCHEMA_SDK];
schemaValidationResult = validator.validate(err, errorSchemaBasedOnMode);
schemaValidationResult = validator.validate(err, errorSchema[errorSchema]);
}
return schemaValidationResult;
}
Expand Down

0 comments on commit 512eb92

Please sign in to comment.