Skip to content

Commit

Permalink
ALPN: check to see if we got the expected protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
elliefm committed Nov 14, 2024
1 parent d1c196a commit 37222a2
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions cassandane/Cassandane/Cyrus/ALPN.pm
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,38 @@ sub do_imap_starttls
}
}

# check if we selected the expected ALPN protocol.
# if the underlying IO::Socket::SSL object isn't accessible, pass undef
# and this check will examine logs instead
sub assert_alpn_protocol
{
my ($self, $socket, $protocol) = @_;

if ($socket) {
if ($protocol) {
$self->assert_str_equals($protocol, $socket->alpn_selected());
}
else {
$self->assert_null($socket->alpn_selected());
}
}
else {
return if !$self->{instance}->{have_syslog_replacement};

my @lines = $self->{instance}->getsyslog(qr{starttls: \S+ with cipher});
$self->assert_num_equals(1, scalar @lines);

if ($protocol) {
$self->assert_matches(qr{; application protocol = $protocol},
$lines[0]);
}
else {
$self->assert_does_not_match(qr{; application protocol =},
$lines[0]);
}
}
}

sub test_imap_none
{
my ($self) = @_;
Expand All @@ -130,6 +162,8 @@ sub test_imap_none

$talk->select("INBOX");
$self->assert_str_equals('ok', $talk->get_last_completion_response());

$self->assert_alpn_protocol($talk->{Socket}, undef);
}

sub test_imap_good
Expand All @@ -147,6 +181,8 @@ sub test_imap_good

$talk->select("INBOX");
$self->assert_str_equals('ok', $talk->get_last_completion_response());

$self->assert_alpn_protocol($talk->{Socket}, 'imap');
}

sub test_imap_bad
Expand Down Expand Up @@ -177,6 +213,8 @@ sub test_imaps_none

$talk->select("INBOX");
$self->assert_str_equals('ok', $talk->get_last_completion_response());

$self->assert_alpn_protocol($talk->{Socket}, undef);
}

sub test_imaps_good
Expand All @@ -189,6 +227,8 @@ sub test_imaps_good

$talk->select("INBOX");
$self->assert_str_equals('ok', $talk->get_last_completion_response());

$self->assert_alpn_protocol($talk->{Socket}, 'imap');
}

sub test_imaps_bad
Expand Down

0 comments on commit 37222a2

Please sign in to comment.