-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add EXPERIMENTAL support for https://ircv3.net/specs/extensions/webirc …
…#346 #444 #546 This implementation allow a Convos admin to set an environment variable to enable WEBIRC. Example: #!/bin/sh export CONVOS_WEBIRC_PASSWORD_LOCALHOST=some_super_secret_password export CONVOS_WEBIRC_PASSWORD_MY_SERVER=some_super_secret_password ./script/convos daemon The part after "CONVOS_WEBIRC_PASSWORD_" is the connection ID, in upper case, without the "irc-" prefix and special characters (such as "-") translated into "_". Setting the environment variable will cause the following IRC commmand to be sent to the server: WEBIRC some_super_secret_password convos <hostname> <ip> "hostname" will fallback to "ip" if the IP could not resolved. IMPORTANT! The "ip" will only update after a USER has gone to the connection settings and hit "Update". The default "ip" (until a user have updated the settings) will be 127.0.0.1. Also, the "ip" will not get updated when the user change IP. It will only get updated when the user actively goes to the connection settings and hit "Update".
- Loading branch information
Jan Henning Thorsen
committed
Jan 12, 2021
1 parent
5dca909
commit 1f9c23b
Showing
5 changed files
with
80 additions
and
24 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,30 @@ | ||
#!perl | ||
BEGIN { $ENV{CONVOS_SKIP_CONNECT} = 1 } | ||
use lib '.'; | ||
use t::Helper; | ||
use t::Server::Irc; | ||
use Convos::Core; | ||
use Convos::Core::Backend::File; | ||
|
||
$ENV{CONVOS_WEBIRC_PASSWORD_EXAMPLE} = 'secret_passphrase'; | ||
|
||
my $server = t::Server::Irc->new->start; | ||
my $core = Convos::Core->new; | ||
my $user = $core->user({email => '[email protected]'}); | ||
$user->save_p->$wait_success; | ||
|
||
my $connection = $user->connection({name => 'example', protocol => 'irc'}); | ||
$connection->save_p->$wait_success; | ||
|
||
$server->client($connection)->server_event_ok( | ||
'_irc_event_webirc', | ||
sub { | ||
my ($connection, $msg) = @_; | ||
is_deeply $msg->{params}, [qw(secret_passphrase convos localhost 127.0.0.1)], 'webirc message'; | ||
} | ||
)->server_event_ok('_irc_event_cap')->server_event_ok('_irc_event_nick') | ||
->server_write_ok(":example CAP * LS :\r\n")->client_event_ok('_irc_event_cap') | ||
->server_write_ok(['welcome.irc'])->client_event_ok('_irc_event_rpl_welcome') | ||
->process_ok('webirc'); | ||
|
||
done_testing; |
This file contains 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 |
---|---|---|
|
@@ -37,30 +37,31 @@ $t->get_ok('/api/connections')->status_is(200)->json_is( | |
protocol => 'irc', | ||
service_accounts => [qw(chanserv nickserv)], | ||
state => 'disconnected', | ||
url => 'irc://irc.example.com:6667', | ||
url => 'irc://irc.example.com:6667?remote_address=127.0.0.1', | ||
wanted_state => 'disconnected', | ||
} | ||
)->json_is('/connections/1/connection_id', 'irc-localhost') | ||
->json_is('/connections/1/name', 'localhost') | ||
->json_is('/connections/1/wanted_state', 'disconnected') | ||
->json_is('/connections/1/url', "irc://localhost:$port"); | ||
->json_is('/connections/1/url', "irc://localhost:$port?remote_address=127.0.0.1"); | ||
|
||
$t->post_ok('/api/connection/irc-doesnotexist', json => {url => 'foo://example.com:9999'}) | ||
->status_is(404); | ||
$t->post_ok('/api/connection/irc-example', json => {})->status_is(200); | ||
|
||
my $connection = $user->get_connection('irc-localhost'); | ||
$t->post_ok('/api/connection/irc-localhost', json => {url => "irc://localhost:$port"}) | ||
->status_is(200)->json_is('/name' => 'localhost')->json_is('/state' => 'disconnected'); | ||
$t->post_ok('/api/connection/irc-localhost', json => {url => 'irc://example.com:9999'}) | ||
->status_is(200)->json_is('/name' => 'localhost') | ||
->json_like('/url' => qr{irc://example\.com:9999}); | ||
$t->post_ok('/api/connection/irc-localhost', | ||
json => {url => "irc://localhost:$port?remote_address=127.0.0.1"})->status_is(200) | ||
->json_is('/name' => 'localhost')->json_is('/state' => 'disconnected'); | ||
$t->post_ok('/api/connection/irc-localhost', | ||
json => {url => 'irc://example.com:9999?remote_address=127.0.0.1'})->status_is(200) | ||
->json_is('/name' => 'localhost')->json_like('/url' => qr{irc://example\.com:9999}); | ||
|
||
$connection->state(disconnected => ''); | ||
$t->post_ok('/api/connection/irc-localhost', | ||
json => {url => 'irc://example.com:9999', wanted_state => 'connected'})->status_is(200) | ||
->json_is('/name' => 'localhost')->json_is('/state' => 'queued') | ||
->json_is('/url' => 'irc://example.com:9999?nick=superman&tls=1'); | ||
->json_is('/url' => 'irc://example.com:9999?remote_address=127.0.0.1&nick=superman&tls=1'); | ||
|
||
$connection->state(connected => ''); | ||
$t->post_ok( | ||
|
@@ -71,26 +72,29 @@ $t->post_ok( | |
} | ||
)->status_is(200)->json_is('/name' => 'localhost')->json_is('/state' => 'connected') | ||
->json_is('/on_connect_commands', ['/msg NickServ identify s3cret', '/msg too_cool 123']) | ||
->json_is('/url' => 'irc://example.com:9999?tls=1&nick=superman'); | ||
->json_is('/url' => 'irc://example.com:9999?tls=1&remote_address=127.0.0.1&nick=superman'); | ||
|
||
$t->post_ok('/api/connection/irc-localhost', | ||
json => {url => 'irc://foo:[email protected]:9999?tls=0&nick=superman'})->status_is(200) | ||
->json_is('/url' => 'irc://foo:[email protected]:9999?tls=0&nick=superman') | ||
->json_is('/url' => 'irc://foo:[email protected]:9999?tls=0&nick=superman&remote_address=127.0.0.1') | ||
->json_is('/state' => 'queued'); | ||
|
||
$connection->state(connected => ''); | ||
$t->post_ok('/api/connection/irc-localhost', | ||
json => | ||
{url => 'irc://foo:[email protected]:9999?tls=0&nick=superman', wanted_state => 'connected'}) | ||
->status_is(200)->json_is('/url' => 'irc://foo:[email protected]:9999?tls=0&nick=superman') | ||
->status_is(200) | ||
->json_is( | ||
'/url' => 'irc://foo:[email protected]:9999?tls=0&nick=superman&remote_address=127.0.0.1') | ||
->json_is('/state' => 'queued'); | ||
|
||
is $connection->TO_JSON(1)->{url}, 'irc://foo:[email protected]:9999?tls=0&nick=superman', | ||
'to json url'; | ||
is $connection->TO_JSON(1)->{url}, | ||
'irc://foo:[email protected]:9999?tls=0&nick=superman&remote_address=127.0.0.1', 'to json url'; | ||
|
||
$t->post_ok('/api/connection/irc-localhost', | ||
json => {url => 'irc://foo:[email protected]:9999?tls=0&nick=superman'})->status_is(200); | ||
is $connection->TO_JSON(1)->{url}, 'irc://foo:[email protected]:9999?tls=0&nick=superman', | ||
is $connection->TO_JSON(1)->{url}, | ||
'irc://foo:[email protected]:9999?tls=0&remote_address=127.0.0.1&nick=superman', | ||
'no change with same username'; | ||
|
||
$t->get_ok('/api/connections')->status_is(200)->json_is('/connections/1/on_connect_commands', | ||
|