1
0
mirror of https://github.com/ACINQ/eclair.git synced 2024-11-20 10:39:19 +01:00

Expose the websocket over HTTP GET to work properly with basic auth (#934)

* Expose the websocket over HTTP GET
* Add test for basic auth over websocket endpoint
This commit is contained in:
araspitzu 2019-04-10 11:07:19 +02:00 committed by GitHub
parent a37fd38d65
commit 3eceb90fa0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 10 deletions

View File

@ -51,6 +51,7 @@ trait Service extends Directives with Logging {
import JsonSupport.marshaller
import JsonSupport.formats
import JsonSupport.serialization
// used to send typed messages over the websocket
val formatsWithTypeHint = formats.withTypeHintFieldName("type") +
CustomTypeHints(Map(
@ -81,7 +82,7 @@ trait Service extends Directives with Logging {
// map all the rejections to a JSON error object ErrorResponse
val apiRejectionHandler = RejectionHandler.default.mapRejectionResponse {
case res @ HttpResponse(_, _, ent: HttpEntity.Strict, _) =>
case res@HttpResponse(_, _, ent: HttpEntity.Strict, _) =>
res.copy(entity = HttpEntity(ContentTypes.`application/json`, serialization.writePretty(ErrorResponse(ent.data.utf8String))))
}
@ -127,7 +128,7 @@ trait Service extends Directives with Logging {
val route: Route = {
respondWithDefaultHeaders(customHeaders) {
handleExceptions(apiExceptionHandler) {
handleRejections(apiRejectionHandler){
handleRejections(apiRejectionHandler) {
withRequestTimeoutResponse(timeoutResponse) {
authenticateBasicAsync(realm = "Access restricted", userPassAuthenticator) { _ =>
post {
@ -244,10 +245,11 @@ trait Service extends Directives with Logging {
} ~
path("channelstats") {
complete(eclairApi.channelStats())
} ~
path("ws") {
handleWebSocketMessages(makeSocketHandler)
}
} ~ get {
path("ws") {
handleWebSocketMessages(makeSocketHandler)
}
}
}
}

View File

@ -260,13 +260,11 @@ class ApiServiceSpec extends FunSuite with ScalatestRouteTest {
val mockService = new MockService(new EclairMock {})
val websocketRoute = Directives.path("ws") {
Directives.handleWebSocketMessages(mockService.makeSocketHandler)
}
val wsClient = WSProbe()
WS("/ws", wsClient.flow) ~> websocketRoute ~>
WS("/ws", wsClient.flow) ~>
addCredentials(BasicHttpCredentials("", mockService.password)) ~>
mockService.route ~>
check {
val pf = PaymentFailed(ByteVector32.Zeroes, failures = Seq.empty)