-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Add Websocket Upgrade Test #5613
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
Open
PoleTransformer
wants to merge
22
commits into
louislam:master
Choose a base branch
from
PoleTransformer:websocket_test
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+406
−10
Open
Changes from 15 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
fc628e3
add websocket test
587699d
Add Websocket Test v2
dcb07a5
update tests
3a61b2f
macos skip insecure test
425c78c
Merge branch 'louislam:master' into websocket_test
PoleTransformer b0fb6ab
linux skip insecure test
2beb627
windows skip insecure test
2d46a32
skip insecure test except generic arm64
1a98012
skip insecure test on CI
bf17e24
increase test verbosity
725892c
increase test verbosity
492d9f5
one assert per testcase
5bca760
local ws for unit test + touchups
2ad0d78
merge wsurl with url
5bc9a0d
add subprotocol selection + translation keys
e3e019c
variable renaming + update translation keys + additional unit tests
2f2db04
Merge branch 'louislam:master' into websocket_test
PoleTransformer 8833b0c
Merge branch 'websocket_test' of github:PoleTransformer/uptime-kuma i…
722a081
fix linter
ee4a34a
add hyperlinks + open new tabs
1f058cb
Merge branch 'master' into websocket_test
CommanderStorm ba7ff48
Merge branch 'master' into websocket_test
CommanderStorm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Add websocket ignore headers and websocket subprotocol | ||
exports.up = function (knex) { | ||
return knex.schema | ||
.alterTable("monitor", function (table) { | ||
table.boolean("ws_ignore_headers").notNullable().defaultTo(false); | ||
table.string("subprotocol", 255).notNullable().defaultTo(""); | ||
}); | ||
}; | ||
|
||
exports.down = function (knex) { | ||
return knex.schema.alterTable("monitor", function (table) { | ||
table.dropColumn("ws_ignore_headers"); | ||
table.dropColumn("subprotocol"); | ||
}); | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
const { MonitorType } = require("./monitor-type"); | ||
const WebSocket = require("ws"); | ||
const { UP, DOWN } = require("../../src/util"); | ||
|
||
class WebSocketMonitorType extends MonitorType { | ||
name = "websocket-upgrade"; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
async check(monitor, heartbeat, _server) { | ||
const [ message, code ] = await this.attemptUpgrade(monitor); | ||
heartbeat.status = code === 1000 ? UP : DOWN; | ||
heartbeat.msg = message; | ||
} | ||
|
||
/** | ||
* Uses the builtin Websocket API to establish a connection to target server | ||
* @param {object} monitor The monitor object for input parameters. | ||
* @returns {[ string, int ]} Array containing a status message and response code | ||
*/ | ||
async attemptUpgrade(monitor) { | ||
return new Promise((resolve) => { | ||
let ws; | ||
//If user selected a subprotocol, sets Sec-WebSocket-Protocol header. Subprotocol Identifier column: https://www.iana.org/assignments/websocket/websocket.xml#subprotocol-name | ||
ws = monitor.subprotocol === "" ? new WebSocket(monitor.url) : new WebSocket(monitor.url, monitor.subprotocol); | ||
|
||
ws.addEventListener("open", (event) => { | ||
// Immediately close the connection | ||
ws.close(1000); | ||
}); | ||
|
||
ws.onerror = (error) => { | ||
// Give user the choice to ignore Sec-WebSocket-Accept header | ||
if (monitor.wsIgnoreHeaders && error.message === "Invalid Sec-WebSocket-Accept header") { | ||
resolve([ "101 - OK", 1000 ]); | ||
} | ||
// Upgrade failed, return message to user | ||
resolve([ error.message, error.code ]); | ||
}; | ||
|
||
ws.onclose = (event) => { | ||
// Upgrade success, connection closed successfully | ||
resolve([ "101 - OK", event.code ]); | ||
}; | ||
}); | ||
} | ||
} | ||
|
||
module.exports = { | ||
WebSocketMonitorType, | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.