chg: add missing openapi endpoints for sync test

pull/86/head
Luciano Righetti 2022-01-26 15:19:23 +01:00
parent 4c60fa0017
commit bd73b620cd
2 changed files with 314 additions and 14 deletions

View File

@ -26,7 +26,8 @@ class MispInterConnectionTest extends TestCase
'app.AuthKeys', 'app.AuthKeys',
'app.Broods', 'app.Broods',
'app.LocalTools', 'app.LocalTools',
'app.RemoteToolConnections' 'app.RemoteToolConnections',
'app.Inbox'
]; ];
/** constants related to the local Cerebrate instance */ /** constants related to the local Cerebrate instance */
@ -46,7 +47,6 @@ class MispInterConnectionTest extends TestCase
public function testInterConnectMispViaCerebrate(): void public function testInterConnectMispViaCerebrate(): void
{ {
$this->skipOpenApiValidations();
$this->initializeWireMock(); $this->initializeWireMock();
$this->setAuthToken(AuthKeysFixture::ADMIN_API_KEY); $this->setAuthToken(AuthKeysFixture::ADMIN_API_KEY);
@ -183,7 +183,6 @@ class MispInterConnectionTest extends TestCase
$this->get(sprintf('/localTools/broodTools/%s', $brood['id'])); $this->get(sprintf('/localTools/broodTools/%s', $brood['id']));
$this->assertResponseOk(); $this->assertResponseOk();
$tools = $this->getJsonResponseAsArray(); $tools = $this->getJsonResponseAsArray();
// print_r($tools);
/** /**
* 5. Issue a connection request to the remote MISP instance * 5. Issue a connection request to the remote MISP instance
@ -250,7 +249,7 @@ class MispInterConnectionTest extends TestCase
'authkey' => $remoteCerebrateAuthkey, 'authkey' => $remoteCerebrateAuthkey,
'url' => self::LOCAL_MISP_INSTANCE_URL, 'url' => self::LOCAL_MISP_INSTANCE_URL,
'name' => 'MISP_LOCAL', 'name' => 'MISP_LOCAL',
'remote_org_id' => 1 'remote_org_id' => OrganisationsFixture::ORGANISATION_A_ID
] ]
); );
$this->post(sprintf('/inbox/process/%s', $acceptRequest['data']['id'])); $this->post(sprintf('/inbox/process/%s', $acceptRequest['data']['id']));
@ -269,9 +268,8 @@ class MispInterConnectionTest extends TestCase
[ [
[ [
"id" => 1, "id" => 1,
"name" => "MISP_REMOTE", "name" => $instance,
"connector" => "MispConnector", "connector" => "MispConnector",
"description" => "Remote MISP instance"
] ]
] ]
))) )))
@ -300,6 +298,7 @@ class MispInterConnectionTest extends TestCase
private function mockMispCreateSyncUser(string $instance, string $mispAuthkey, int $userId, string $email): \WireMock\Stubbing\StubMapping private function mockMispCreateSyncUser(string $instance, string $mispAuthkey, int $userId, string $email): \WireMock\Stubbing\StubMapping
{ {
$faker = \Faker\Factory::create();
return $this->getWireMock()->stubFor( return $this->getWireMock()->stubFor(
WireMock::post(WireMock::urlEqualTo("/$instance/admin/users/add")) WireMock::post(WireMock::urlEqualTo("/$instance/admin/users/add"))
->withHeader('Authorization', WireMock::equalTo($mispAuthkey)) ->withHeader('Authorization', WireMock::equalTo($mispAuthkey))
@ -309,7 +308,8 @@ class MispInterConnectionTest extends TestCase
[ [
"User" => [ "User" => [
"id" => $userId, "id" => $userId,
"email" => $email "email" => $email,
"authkey" => $faker->sha1
] ]
] ]
))) )))

View File

@ -27,6 +27,8 @@ tags:
description: "Assign encryption keys to the user, used to securely communicate or validate messages coming from the user." description: "Assign encryption keys to the user, used to securely communicate or validate messages coming from the user."
- name: AuthKeys - name: AuthKeys
description: "Authkeys are used for API access. A user can have more than one authkey, so if you would like to use separate keys per tool that queries Cerebrate, add additional keys. Use the comment field to make identifying your keys easier." description: "Authkeys are used for API access. A user can have more than one authkey, so if you would like to use separate keys per tool that queries Cerebrate, add additional keys. Use the comment field to make identifying your keys easier."
- name: LocalTools
description: "Cerebrate can connect to local tools via individual connectors, built to expose the various functionalities of the given tool via Cerebrate. Simply view the connectors' details and the accompanying instance list to manage the connections using the given connector."
paths: paths:
/individuals/index: /individuals/index:
@ -418,7 +420,7 @@ paths:
/inbox/createEntry/User/Registration: /inbox/createEntry/User/Registration:
post: post:
summary: "Create user registration inbox entry" summary: "Create user registration inbox entry"
operationId: createInboxEntry operationId: createUserRegistrationInboxEntry
tags: tags:
- Inbox - Inbox
requestBody: requestBody:
@ -433,6 +435,42 @@ paths:
default: default:
$ref: "#/components/responses/ApiErrorResponse" $ref: "#/components/responses/ApiErrorResponse"
/inbox/createEntry/LocalTool/AcceptedRequest:
post:
summary: "Create accepted connection request inbox entry"
operationId: createAcceptedRequestInboxEntry
tags:
- Inbox
requestBody:
$ref: "#/components/requestBodies/CreateAcceptedRequestInboxEntryRequest"
responses:
"200":
$ref: "#/components/responses/AcceptedRequestInboxResponse"
"403":
$ref: "#/components/responses/UnauthorizedApiErrorResponse"
"405":
$ref: "#/components/responses/MethodNotAllowedApiErrorResponse"
default:
$ref: "#/components/responses/ApiErrorResponse"
/inbox/process/{inboxId}:
post:
summary: "Process inbox entry"
operationId: processInboxEntry
tags:
- Inbox
parameters:
- $ref: "#/components/parameters/inboxId"
responses:
"200":
$ref: "#/components/responses/ProcessInboxResponse"
"403":
$ref: "#/components/responses/UnauthorizedApiErrorResponse"
"405":
$ref: "#/components/responses/MethodNotAllowedApiErrorResponse"
default:
$ref: "#/components/responses/ApiErrorResponse"
/sharingGroups/index: /sharingGroups/index:
get: get:
summary: "Get a sharing groups list" summary: "Get a sharing groups list"
@ -783,6 +821,63 @@ paths:
default: default:
$ref: "#/components/responses/ApiErrorResponse" $ref: "#/components/responses/ApiErrorResponse"
/localTools/add:
post:
summary: "Add a local tool connection"
operationId: addLocalTool
tags:
- LocalTools
requestBody:
$ref: "#/components/requestBodies/CreateLocalToolConnectionRequest"
responses:
"200":
$ref: "#/components/responses/LocalToolResponse"
"403":
$ref: "#/components/responses/UnauthorizedApiErrorResponse"
"405":
$ref: "#/components/responses/MethodNotAllowedApiErrorResponse"
default:
$ref: "#/components/responses/ApiErrorResponse"
/localTools/broodTools/{broodId}:
get:
summary: "Get brood exposed tools"
operationId: getBroodExposedTools
tags:
- LocalTools
parameters:
- $ref: "#/components/parameters/broodId"
responses:
"200":
$ref: "#/components/responses/GetExposedBroodToolsResponse"
"403":
$ref: "#/components/responses/UnauthorizedApiErrorResponse"
"405":
$ref: "#/components/responses/MethodNotAllowedApiErrorResponse"
default:
$ref: "#/components/responses/ApiErrorResponse"
/localTools/connectionRequest/{broodId}/{localToolId}:
post:
summary: "Issue a local tool connection request"
operationId: issueLocalToolConnectionRequest
tags:
- LocalTools
parameters:
- $ref: "#/components/parameters/broodId"
- $ref: "#/components/parameters/localToolId"
requestBody:
$ref: "#/components/requestBodies/IssueLocalToolConnectionRequest"
responses:
"200":
$ref: "#/components/responses/IncomingConnectionRequestInboxResponse"
"403":
$ref: "#/components/responses/UnauthorizedApiErrorResponse"
"405":
$ref: "#/components/responses/MethodNotAllowedApiErrorResponse"
default:
$ref: "#/components/responses/ApiErrorResponse"
components: components:
schemas: schemas:
# General # General
@ -1129,8 +1224,37 @@ components:
user: user:
$ref: "#/components/schemas/User" $ref: "#/components/schemas/User"
local_tool_connector_name: local_tool_connector_name:
type: string $ref: "#/components/schemas/LocalToolConnector"
nullable: true
AcceptedRequestInbox:
type: object
allOf:
- $ref: "#/components/schemas/Inbox"
- type: object
properties:
data:
type: object
properties:
email:
$ref: "#/components/schemas/Email"
authkey:
$ref: "#/components/schemas/AuthKeyRaw"
url:
type: string
reflected_user_id:
$ref: "#/components/schemas/ID"
connectorName:
$ref: "#/components/schemas/LocalToolConnector"
cerebrateURL:
type: string
local_tool_id:
$ref: "#/components/schemas/ID"
remote_tool_id:
$ref: "#/components/schemas/ID"
tool_name:
type: string
local_tool_connector_name:
$ref: "#/components/schemas/LocalToolConnector"
IncomingConnectionRequestInbox: IncomingConnectionRequestInbox:
type: object type: object
@ -1142,9 +1266,7 @@ components:
type: object type: object
properties: properties:
connectorName: connectorName:
type: string $ref: "#/components/schemas/LocalToolConnector"
enum:
- "MispConnector"
cerebrateURL: cerebrateURL:
type: string type: string
example: "http://192.168.0.1" example: "http://192.168.0.1"
@ -1159,6 +1281,7 @@ components:
anyOf: anyOf:
- $ref: "#/components/schemas/UserRegistrationInbox" - $ref: "#/components/schemas/UserRegistrationInbox"
- $ref: "#/components/schemas/IncomingConnectionRequestInbox" - $ref: "#/components/schemas/IncomingConnectionRequestInbox"
- $ref: "#/components/schemas/AcceptedRequestInbox"
# SharingGroups # SharingGroups
SharingGroupName: SharingGroupName:
@ -1362,6 +1485,45 @@ components:
items: items:
$ref: "#/components/schemas/AuthKey" $ref: "#/components/schemas/AuthKey"
# LocalTools
LocalToolName:
type: string
LocalToolConnector:
type: string
nullable: true
enum:
- "MispConnector"
LocalToolSettings:
type: string
description: "Stringified JSON representing tool settings"
LocalToolDescription:
type: string
LocalToolIsExposed:
type: boolean
LocalTool:
type: object
properties:
name:
$ref: "#/components/schemas/LocalToolName"
connector:
$ref: "#/components/schemas/LocalToolConnector"
settings:
$ref: "#/components/schemas/LocalToolSettings"
description:
$ref: "#/components/schemas/LocalToolDescription"
exposed:
$ref: "#/components/schemas/LocalToolIsExposed"
LocalToolList:
type: array
items:
$ref: "#/components/schemas/LocalTool"
# Errors # Errors
ApiError: ApiError:
type: object type: object
@ -1487,6 +1649,22 @@ components:
schema: schema:
$ref: "#/components/schemas/ID" $ref: "#/components/schemas/ID"
localToolId:
name: localToolId
in: path
description: "Numeric ID of the local tool"
required: true
schema:
$ref: "#/components/schemas/ID"
inboxId:
name: inboxId
in: path
description: "Numeric ID of the local tool"
required: true
schema:
$ref: "#/components/schemas/ID"
quickFilter: quickFilter:
name: quickFilter name: quickFilter
in: query in: query
@ -1669,6 +1847,32 @@ components:
password: password:
type: string type: string
CreateAcceptedRequestInboxEntryRequest:
description: "Create accepted connection request inbox entry request"
content:
application/json:
schema:
type: object
properties:
email:
$ref: "#/components/schemas/Email"
authkey:
$ref: "#/components/schemas/AuthKeyRaw"
url:
type: string
reflected_user_id:
$ref: "#/components/schemas/ID"
connectorName:
$ref: "#/components/schemas/LocalToolConnector"
cerebrateURL:
type: string
local_tool_id:
$ref: "#/components/schemas/ID"
remote_tool_id:
$ref: "#/components/schemas/ID"
tool_name:
type: string
# SharingGroups # SharingGroups
CreateSharingGroupRequest: CreateSharingGroupRequest:
required: true required: true
@ -1834,6 +2038,34 @@ components:
comment: comment:
$ref: "#/components/schemas/AuthKeyComment" $ref: "#/components/schemas/AuthKeyComment"
# LocalTools
CreateLocalToolConnectionRequest:
required: true
content:
application/json:
schema:
type: object
properties:
name:
$ref: "#/components/schemas/LocalToolName"
connector:
$ref: "#/components/schemas/LocalToolConnector"
settings:
$ref: "#/components/schemas/LocalToolSettings"
description:
$ref: "#/components/schemas/LocalToolDescription"
exposed:
$ref: "#/components/schemas/LocalToolIsExposed"
IssueLocalToolConnectionRequest:
required: true
content:
application/json:
schema:
type: object
properties:
local_tool_id:
type: integer
responses: responses:
# Individuals # Individuals
IndividualResponse: IndividualResponse:
@ -1910,6 +2142,34 @@ components:
schema: schema:
$ref: "#/components/schemas/IncomingConnectionRequestInbox" $ref: "#/components/schemas/IncomingConnectionRequestInbox"
AcceptedRequestInboxResponse:
description: "Accepted connection request inbox response"
content:
application/json:
schema:
$ref: "#/components/schemas/IncomingConnectionRequestInbox"
ProcessInboxResponse:
description: "Process inbox response"
content:
application/json:
schema:
type: object
properties:
data:
type: object
properties:
success:
type: boolean
success:
type: boolean
message:
type: string
example: "Interconnection for `http://cerebrate.remote`'s finalised"
errors:
type: string
nullable: true
InboxListResponse: InboxListResponse:
description: "Inbox list response" description: "Inbox list response"
content: content:
@ -1918,7 +2178,7 @@ components:
$ref: "#/components/schemas/InboxList" $ref: "#/components/schemas/InboxList"
CreateUserRegistrationInboxEntryResponse: CreateUserRegistrationInboxEntryResponse:
description: "Inbox response" description: "Create user registration inbox response"
content: content:
application/json: application/json:
schema: schema:
@ -1942,6 +2202,31 @@ components:
type: object type: object
# TODO: describe # TODO: describe
AcceptedRequestInboxEntryResponse:
description: "Accepted request inbox response"
content:
application/json:
schema:
type: object
properties:
data:
allOf:
- $ref: "#/components/schemas/AcceptedRequestInbox"
- properties:
local_tool_connector_name:
type: string
nullable: true
success:
type: boolean
message:
type: string
example: "User account creation requested. Please wait for an admin to approve your account."
errors:
type: array
items:
type: object
# TODO: describe
# SharingGroups # SharingGroups
SharingGroupResponse: SharingGroupResponse:
description: "Sharing group response" description: "Sharing group response"
@ -2029,6 +2314,21 @@ components:
schema: schema:
$ref: "#/components/schemas/AuthKeyList" $ref: "#/components/schemas/AuthKeyList"
# LocalTools
LocalToolResponse:
description: "Local tool response"
content:
application/json:
schema:
$ref: "#/components/schemas/LocalTool"
GetExposedBroodToolsResponse:
description: "Local tool response"
content:
application/json:
schema:
$ref: "#/components/schemas/LocalToolList"
# Errors # Errors
ApiErrorResponse: ApiErrorResponse:
description: "Unexpected API error" description: "Unexpected API error"