Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Autobahn/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.build
Package.resolved
run.sh
Dockerfile
reports
config
5 changes: 5 additions & 0 deletions Autobahn/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.DS_Store
/.build
/Packages
/*.xcodeproj
xcuserdata/
11 changes: 11 additions & 0 deletions Autobahn/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM swift:5.1

RUN apt-get update && apt-get install -y libssl-dev libcurl4-openssl-dev libz-dev

COPY . /WebSocketEchoServer

WORKDIR /WebSocketEchoServer

RUN swift build
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Release mode? Or not...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hmm good question. I'd gone for debug mode since we're dealing with tests, but as this is essentially acceptance testing, perhaps it should be release mode.


CMD .build/debug/WebSocketEchoServer
16 changes: 16 additions & 0 deletions Autobahn/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// swift-tools-version:5.1
import PackageDescription

let package = Package(
name: "WebSocketEchoServer",
dependencies: [
.package(url: "https://github.com/IBM-Swift/Kitura.git", from: "2.8.0"),
.package(url: "https://github.com/IBM-Swift/HeliumLogger.git", from: "1.7.0"),
.package(url: "https://github.com/IBM-Swift/Kitura-WebSocket.git", from: "2.0.0")
],
targets: [
.target(
name: "WebSocketEchoServer",
dependencies: ["Kitura", "HeliumLogger", "Kitura-WebSocket"]),
]
)
3 changes: 3 additions & 0 deletions Autobahn/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Autobahn

A description of this package.
25 changes: 25 additions & 0 deletions Autobahn/Sources/WebSocketEchoServer/EchoService.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import Foundation

import KituraWebSocket
import LoggerAPI

class EchoService: WebSocketService {

public func connected(connection: WebSocketConnection) {}

public func disconnected(connection: WebSocketConnection, reason: WebSocketCloseReasonCode) {}

public func received(message: Data, from: WebSocketConnection) {
from.send(message: message)
}

public func received(message: String, from: WebSocketConnection) {
let msgLength = message.utf8.count
if msgLength > 100 {
Log.info("Got message of length \(msgLength)... sending it back")
} else {
Log.info("Got message '\(message)'... sending it back")
}
from.send(message: message)
}
}
16 changes: 16 additions & 0 deletions Autobahn/Sources/WebSocketEchoServer/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import Foundation
import Kitura
import KituraWebSocket
import HeliumLogger

// Using an implementation for a Logger
HeliumLogger.use(.info)

let router = Router()

WebSocket.register(service: EchoService(), onPath: "/")

let port = 9001

Kitura.addHTTPServer(onPort: port, with: router)
Kitura.run()
11 changes: 11 additions & 0 deletions Autobahn/config/fuzzingclient.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"outdir": "./reports/servers",
"servers": [
{
"url": "ws://wsserver:9001"
}
],
"cases": ["*"],
"exclude-cases": [],
"exclude-agent-cases": {}
}
33 changes: 33 additions & 0 deletions Autobahn/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash
#
# Convenience script to build and run a Kitura-WebSocket echo server in a Docker container,
# and then to run the autobahn test suite Docker container against it.
#
# Once complete, the autobahn report (HTML format) will be opened.
#

# Create network
docker network rm autobahn
docker network create --driver bridge autobahn

# Build server
docker build -t wsserver .

# Execute server
docker container rm wsserver
docker run -d --network autobahn --name wsserver wsserver

# Execute client
docker run -it --rm \
-v ${PWD}/config:/config \
-v ${PWD}/reports:/reports \
--name fuzzingclient \
--network autobahn \
crossbario/autobahn-testsuite \
wstest -m fuzzingclient -s config/fuzzingclient.json

# Stop server
docker container stop wsserver

# Check out test report!
open ./reports/servers/index.html
6 changes: 6 additions & 0 deletions AutobahnTests.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

This document will take you through the steps to test Kitura-Websockets using [autobahn-testsuite](https://github.com/crossbario/autobahn-testsuite).

### Convenience (ready-to-run) Docker implementation

For convenience, a project is provided in `Autobahn/` that implements the code below.

A script `Autobahn/run.sh` is included that will build this within a Docker container, run the container, and then run the autobahn test suite (in client mode) against this server.

### Creating a EchoServer
These tests are run against a WebSocket EchoServer so we must first set one up.

Expand Down