inth-oauth2/tests/auth_uri.rs

67 lines
1.8 KiB
Rust
Raw Normal View History

2017-08-23 06:39:49 +00:00
extern crate reqwest;
2015-12-26 02:35:21 +00:00
extern crate inth_oauth2;
extern crate url;
2015-12-26 02:35:21 +00:00
use inth_oauth2::Client;
use inth_oauth2::provider::*;
use url::Url;
2015-12-26 02:35:21 +00:00
fn assert_get_uri_ok(uri: Url) {
2017-08-23 06:39:49 +00:00
let response = reqwest::get(uri).unwrap();
assert_eq!(reqwest::StatusCode::Ok, response.status());
2015-12-26 02:35:21 +00:00
}
2016-02-28 00:22:47 +00:00
#[test]
fn google_web_auth_uri_ok() {
2017-08-23 18:09:05 +00:00
let client = Client::new(
google::Web,
2016-02-28 00:22:47 +00:00
String::from("143225766783-0h4h5ktpvhc7kqp6ohbpd2sssqrap57n.apps.googleusercontent.com"),
String::new(),
Some(String::from("https://cmcenroe.me/oauth2-paste/")),
);
let auth_uri = client.auth_uri(
Some("https://www.googleapis.com/auth/userinfo.email"),
Some("state"),
).unwrap();
assert_get_uri_ok(auth_uri);
2016-02-28 00:22:47 +00:00
}
2015-12-26 02:35:21 +00:00
#[test]
fn google_installed_auth_uri_ok() {
2017-08-23 18:09:05 +00:00
let client = Client::new(
google::Installed,
2016-01-29 02:54:14 +00:00
String::from("143225766783-ip2d9qv6sdr37276t77luk6f7bhd6bj5.apps.googleusercontent.com"),
String::new(),
2017-08-23 18:09:05 +00:00
Some(String::from("urn:ietf:wg:oauth:2.0:oob")),
2015-12-26 02:35:21 +00:00
);
let auth_uri = client.auth_uri(
Some("https://www.googleapis.com/auth/userinfo.email"),
2017-08-23 18:09:05 +00:00
Some("state"),
2015-12-26 02:35:21 +00:00
).unwrap();
assert_get_uri_ok(auth_uri);
2015-12-26 02:35:21 +00:00
}
#[test]
fn github_auth_uri_ok() {
2017-08-23 18:09:05 +00:00
let client = Client::new(
GitHub,
2016-01-29 02:54:14 +00:00
String::from("01774654cd9a6051e478"),
String::new(),
2017-08-23 18:09:05 +00:00
Some(String::from("https://cmcenroe.me/oauth2-paste/")),
2015-12-26 02:35:21 +00:00
);
let auth_uri = client.auth_uri(Some("user"), Some("state")).unwrap();
assert_get_uri_ok(auth_uri);
2015-12-26 02:35:21 +00:00
}
#[test]
fn imgur_auth_uri_ok() {
2017-08-23 18:09:05 +00:00
let client = Client::new(
Imgur,
2016-01-29 02:54:14 +00:00
String::from("505c8ca804230e0"),
String::new(),
2017-08-23 18:09:05 +00:00
Some(String::from("https://cmcenroe.me/oauth2-paste/")),
2015-12-26 02:35:21 +00:00
);
let auth_uri = client.auth_uri(None, Some("state")).unwrap();
assert_get_uri_ok(auth_uri);
2015-12-26 02:35:21 +00:00
}