Skip to content

Commit

Permalink
tests: cover uncovered security definitions validation
Browse files Browse the repository at this point in the history
  • Loading branch information
DenTray committed Oct 28, 2023
1 parent 58b1b8f commit 80b9853
Show file tree
Hide file tree
Showing 5 changed files with 282 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Validators/SwaggerSpecValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ protected function validateSecurityDefinitions(): void

$this->validateFieldsPresent(self::REQUIRED_FIELDS['security_definition'], $parentId);

$this->validateFieldValue("{$parentId}.'type", self::ALLOWED_VALUES['security_definition_type']);
$this->validateFieldValue("{$parentId}.'in", self::ALLOWED_VALUES['security_definition_in']);
$this->validateFieldValue("{$parentId}.'flow", self::ALLOWED_VALUES['security_definition_flow']);
$this->validateFieldValue("{$parentId}.type", self::ALLOWED_VALUES['security_definition_type']);
$this->validateFieldValue("{$parentId}.in", self::ALLOWED_VALUES['security_definition_in']);
$this->validateFieldValue("{$parentId}.flow", self::ALLOWED_VALUES['security_definition_flow']);
}
}

Expand Down
15 changes: 15 additions & 0 deletions tests/SwaggerServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,21 @@ public function getConstructorInvalidTmpData(): array
'exceptionMessage' => "Validation failed. Path parameters cannot be optional. "
. "Set required=true for the 'username' parameters at operation 'paths./users.get'."
],
[
'tmpDoc' => 'documentation/invalid_format__security_definition__type',
'exception' => InvalidSwaggerSpecException::class,
'exceptionMessage' => "Validation failed. Field 'securityDefinitions.0.type' has an invalid value: invalid. Allowed values: basic, apiKey, oauth2."
],
[
'tmpDoc' => 'documentation/invalid_format__security_definition__flow',
'exception' => InvalidSwaggerSpecException::class,
'exceptionMessage' => "Validation failed. Field 'securityDefinitions.0.flow' has an invalid value: invalid. Allowed values: implicit, password, application, accessCode."
],
[
'tmpDoc' => 'documentation/invalid_format__security_definition__in',
'exception' => InvalidSwaggerSpecException::class,
'exceptionMessage' => "Validation failed. Field 'securityDefinitions.0.in' has an invalid value: invalid. Allowed values: query, header."
],
];
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
{
"swagger": "2.0",
"host": "localhost",
"basePath": "\/",
"schemes": [],
"paths": {
"\/api\/users":
{
"post":
{
"tags": ["api"],
"consumes": ["application\/x-www-form-urlencoded"],
"produces": ["application\/json"],
"parameters": [
{
"in": "body",
"name": "body",
"description": "",
"required": true,
"schema": {
"$ref": "#/definitions/apiusersObject"
}
}
],
"responses":
{
"403":
{
"description": "Forbidden",
"schema":
{
"example":
{
"message": "This action is unauthorized."
}
}
}
},
"security": [],
"description": "",
"summary": "test"
}
}
},
"definitions": {
"apiusersObject": {
"type": "object",
"properties": {
"query": {
"type": "string",
"description": ""
},
"user_id": {
"type": "integer",
"description": "with_to_array_rule_string_name"
},
"is_email_enabled": {
"type": "string",
"description": "test_rule_without_to_string"
}
},
"required": {
"0": "query"
},
"example": {
"first_name": "andrey",
"last_name": "voronin"
}
}
},
"info": {
"description": "This is automatically collected documentation",
"version": "0.0.0",
"title": "Name of Your Application",
"termsOfService": "",
"contact":
{
"email": "[email protected]"
}
},
"securityDefinitions": [
{
"type": "basic",
"in": "query",
"flow": "invalid"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
{
"swagger": "2.0",
"host": "localhost",
"basePath": "\/",
"schemes": [],
"paths": {
"\/api\/users":
{
"post":
{
"tags": ["api"],
"consumes": ["application\/x-www-form-urlencoded"],
"produces": ["application\/json"],
"parameters": [
{
"in": "body",
"name": "body",
"description": "",
"required": true,
"schema": {
"$ref": "#/definitions/apiusersObject"
}
}
],
"responses":
{
"403":
{
"description": "Forbidden",
"schema":
{
"example":
{
"message": "This action is unauthorized."
}
}
}
},
"security": [],
"description": "",
"summary": "test"
}
}
},
"definitions": {
"apiusersObject": {
"type": "object",
"properties": {
"query": {
"type": "string",
"description": ""
},
"user_id": {
"type": "integer",
"description": "with_to_array_rule_string_name"
},
"is_email_enabled": {
"type": "string",
"description": "test_rule_without_to_string"
}
},
"required": {
"0": "query"
},
"example": {
"first_name": "andrey",
"last_name": "voronin"
}
}
},
"info": {
"description": "This is automatically collected documentation",
"version": "0.0.0",
"title": "Name of Your Application",
"termsOfService": "",
"contact":
{
"email": "[email protected]"
}
},
"securityDefinitions": [
{
"type": "basic",
"in": "invalid",
"flow": "password"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
{
"swagger": "2.0",
"host": "localhost",
"basePath": "\/",
"schemes": [],
"paths": {
"\/api\/users":
{
"post":
{
"tags": ["api"],
"consumes": ["application\/x-www-form-urlencoded"],
"produces": ["application\/json"],
"parameters": [
{
"in": "body",
"name": "body",
"description": "",
"required": true,
"schema": {
"$ref": "#/definitions/apiusersObject"
}
}
],
"responses":
{
"403":
{
"description": "Forbidden",
"schema":
{
"example":
{
"message": "This action is unauthorized."
}
}
}
},
"security": [],
"description": "",
"summary": "test"
}
}
},
"definitions": {
"apiusersObject": {
"type": "object",
"properties": {
"query": {
"type": "string",
"description": ""
},
"user_id": {
"type": "integer",
"description": "with_to_array_rule_string_name"
},
"is_email_enabled": {
"type": "string",
"description": "test_rule_without_to_string"
}
},
"required": {
"0": "query"
},
"example": {
"first_name": "andrey",
"last_name": "voronin"
}
}
},
"info": {
"description": "This is automatically collected documentation",
"version": "0.0.0",
"title": "Name of Your Application",
"termsOfService": "",
"contact":
{
"email": "[email protected]"
}
},
"securityDefinitions": [
{
"type": "invalid",
"in": "query",
"flow": "password"
}
]
}

0 comments on commit 80b9853

Please sign in to comment.