File tree Expand file tree Collapse file tree 2 files changed +41
-3
lines changed
lib/net/imap/authenticators Expand file tree Collapse file tree 2 files changed +41
-3
lines changed Original file line number Diff line number Diff line change 44#
55# See RFC4616[https://tools.ietf.org/html/rfc4616] for the specification.
66class Net ::IMAP ::PlainAuthenticator
7+
78 def process ( data )
8- return "\0 #{ @user } \0 #{ @password } "
9+ return "# @authzid \0 #@username \0 #@password "
910 end
1011
12+ NULL = -"\0 " . b
13+
1114 private
1215
13- def initialize ( user , password )
14- @user = user
16+ # +username+ is the authentication identity, the identity whose +password+ is
17+ # used. +username+ is referred to as +authcid+ by
18+ # RFC4616[https://tools.ietf.org/html/rfc4616].
19+ #
20+ # +authzid+ is the authorization identity (identity to act as). It can
21+ # usually be left blank. When +authzid+ is left blank (nil or empty string)
22+ # the server will derive an identity from the credentials and use that as the
23+ # authorization identity.
24+ def initialize ( username , password , authzid : nil )
25+ raise ArgumentError , "username contains NULL" if username &.include? ( NULL )
26+ raise ArgumentError , "password contains NULL" if password &.include? ( NULL )
27+ raise ArgumentError , "authzid contains NULL" if authzid &.include? ( NULL )
28+ @username = username
1529 @password = password
30+ @authzid = authzid
1631 end
1732
1833 Net ::IMAP . add_authenticator "PLAIN" , self
Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
3+ require "net/imap"
4+ require "test/unit"
5+
6+ class IMAPAuthenticatorsTest < Test ::Unit ::TestCase
7+
8+ PLAIN = Net ::IMAP ::PlainAuthenticator
9+
10+ def test_plain
11+ assert_equal ( "\0 authc\0 passwd" ,
12+ PLAIN . new ( "authc" , "passwd" ) . process ( nil ) )
13+ assert_equal ( "authz\0 user\0 pass" ,
14+ PLAIN . new ( "user" , "pass" , authzid : "authz" ) . process ( nil ) )
15+ end
16+
17+ def test_plain_no_null_chars
18+ assert_raise ( ArgumentError ) { PLAIN . new ( "bad\0 user" , "pass" ) }
19+ assert_raise ( ArgumentError ) { PLAIN . new ( "user" , "bad\0 pass" ) }
20+ assert_raise ( ArgumentError ) { PLAIN . new ( "u" , "p" , authzid : "bad\0 authz" ) }
21+ end
22+
23+ end
You can’t perform that action at this time.
0 commit comments