Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor http API handler, add test #199

Merged

Conversation

vixentael
Copy link
Collaborator

  • add tests for HTTP response codes
  • refactor HTTP handler into smaller functions

@vixentael vixentael requested a review from Lagovas July 12, 2018 12:18
if zoneId != nil {
privateKey, err = server.keystorage.GetZonePrivateKey(zoneId)
} else {
privateKey, err = server.keystorage.GetZonePrivateKey(clientId)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetZonePrivateKey -> GetServerDecryptionPrivateKey

}


func (server *ReaderServer) closeConnectionAndSendResponse(logger *log.Entry, response *http.Response, connection net.Conn) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to sendResponseAndCloseConnection ?)

logger.WithError(err).WithField(logging.FieldKeyEventCode, logging.EventCodeErrorReaderCantReturnResponse).
Warningln("Can't write response to HTTP request")
} else {
connection.Write(buf.Bytes())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

log errors on write

connection.Write(buf.Bytes())
}

connection.Close()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

log errors on close

request.URL, _ = url.Parse("http://smth.com/v1/decrypt?zone_id=\"somezoneid\"")
request.Body = ioutil.NopCloser(bytes.NewBufferString("bla bla bla body"))
res = readerServer.parseRequestPrepareResponse(logger, &request, []byte("asdf"))
if res.StatusCode != http.StatusUnprocessableEntity {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check decryption success request too?)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it depends on keystorage, masterkey and folders. is there any way to mock keystorage behaviour (to override getting private keys functiont)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's just interface and you can add simple as you need implementation for tests (example https://github.com/cossacklabs/acra/pull/200/files#diff-2a5db1c46f9ea9f86e34328a7bbc0dc6R13)

}

// /v1/decrypt
// /, v1, decrypt
pathParts := strings.Split(request.URL.Path, string(os.PathSeparator))
if len(pathParts) != 3 {
logger.WithError(err).WithField(logging.FieldKeyEventCode, logging.EventCodeErrorReaderMalformedURL).
logger.WithField(logging.FieldKeyEventCode, logging.EventCodeErrorReaderMalformedURL).
Warningf("Malformed URL, expected /<version>/<endpoint>, got %s", request.URL.Path)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we place this explanation to response body to simplify understanding of errors by clients?

@vixentael vixentael merged commit 438a4c2 into new/acra-reader-T663 Jul 13, 2018
@vixentael vixentael deleted the vixentael/acra-reader-http-refactoring branch July 13, 2018 10:30
vixentael added a commit that referenced this pull request Jul 23, 2018
* acra reader: entry point

* deadline listener; refactor acra-server

* base part of connection handling (#197)

* base part of connection handling

* save connections by descriptor

* add a little bit graceful stop service

* basic http /decrypt handle (#198)

* refactor http API handler, add test (#199)

* refactor http API handler, add test

* validate acrastruct length before decryption (#201)

* add more errors checking

* copy keys in test keystorage, add tests on encryption

* move into separate folder; add http message responses in body

* grpc handler (#200)

* change sign of comparison key length

* base part of connection handling

* save connections by descriptor

* add a little bit graceful stop service

* add grpc service

* fix log message

* fix import path

* add missing file

* validate acrastruct length before decryption

* add api test

* drop old method
fill with zeroes private key

* verbose go get

* rename api -> grpc_api

* fix network part (#203)

* fix accepting connections, network manager

* drop comment

* AcraReader http buffering (#204)

* fixing http handling

* close connection, remove buffers for http response

* add more logs to decryptor

* move defer to the top

* acra-reader -> acra-translator renaming (#205)

* acra-reader -> acra-translator

* re-gen api.pb.go

* rm old file

* Update AcraConnector to connect with AcraTranslator (#206)

* acra-reader -> acra-translator

* re-gen api.pb.go

* add separate acra-translator keys

* simplify keys check

* acra reader integration tests [T663] (#207)

* integration tests for grpc/http

* refactor serializing http response struct

* check response codes and messages in tests

* compare all messages in lower case

* add translator keystore
move filesystem keystore to separate package
run translator with own transport keys

* fix import in unit test

* return error code after failed creation of posion record

* drop keys folder before tests

* set Connection: close header to http response

* optimize response sending

* deadline for secure session handshake
timeout for http requests in tests

* refactor tests of acra-connector shutdown

* detect poison record on translator (#212)

* check poison records on acra-translator

* change path to test master key

* update log messages
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants