imap::client::Client::authenticate: Base64 encode the result of the Authenticator.
Fixes issue #95.
This commit is contained in:
parent
b45beb88ed
commit
93d032181d
2 changed files with 24 additions and 3 deletions
|
|
@ -30,6 +30,4 @@ regex = "1.0"
|
|||
bufstream = "0.1"
|
||||
imap-proto = "0.6"
|
||||
nom = "4.0"
|
||||
|
||||
[dev-dependencies]
|
||||
base64 = "0.10"
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
extern crate base64;
|
||||
use bufstream::BufStream;
|
||||
use native_tls::{TlsConnector, TlsStream};
|
||||
use nom;
|
||||
|
|
@ -394,7 +395,7 @@ impl<T: Read + Write> Client<T> {
|
|||
parse_authenticate_response(String::from_utf8(line).unwrap()),
|
||||
self
|
||||
);
|
||||
let auth_response = authenticator.process(data);
|
||||
let auth_response = base64::encode(authenticator.process(data).as_str());
|
||||
|
||||
ok_or_unauth_client_err!(
|
||||
self.write_line(auth_response.into_bytes().as_slice()),
|
||||
|
|
@ -937,6 +938,28 @@ mod tests {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn authenticate() {
|
||||
let response = b"+\r\n\
|
||||
a1 OK Logged in\r\n".to_vec();
|
||||
let command = "a1 AUTHENTICATE PLAIN\r\n\
|
||||
Zm9v\r\n";
|
||||
let mock_stream = MockStream::new(response);
|
||||
let client = Client::new(mock_stream);
|
||||
enum Authenticate { Auth };
|
||||
impl Authenticator for Authenticate {
|
||||
fn process(&self, _: String) -> String {
|
||||
"foo".to_string()
|
||||
}
|
||||
}
|
||||
let auth = Authenticate::Auth;
|
||||
let session = client.authenticate("PLAIN", auth).unwrap();
|
||||
assert!(
|
||||
session.stream.get_ref().written_buf == command.as_bytes().to_vec(),
|
||||
"Invalid authenticate command"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn login() {
|
||||
let response = b"a1 OK Logged in\r\n".to_vec();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue