-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Partially complete update to add API tokens to tests (checkpt)
- Loading branch information
Showing
3 changed files
with
125 additions
and
35 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,44 +67,58 @@ fn client_server_integration( | |
|
||
// Register an entity. | ||
Command::cargo_bin("ayb")? | ||
.args(["client", "register", "e2e", "[email protected]"]) | ||
.args(["client", "register", "e2e-first", "[email protected]"]) | ||
.env("AYB_SERVER_URL", server_url) | ||
.assert() | ||
.success() | ||
.stdout("Check your email to finish registering e2e\n"); | ||
.stdout("Check your email to finish registering e2e-first\n"); | ||
|
||
// Register the same entity with the same email address. | ||
Command::cargo_bin("ayb")? | ||
.args(["client", "register", "e2e", "[email protected]"]) | ||
.args(["client", "register", "e2e-first", "[email protected]"]) | ||
.env("AYB_SERVER_URL", server_url) | ||
.assert() | ||
.success() | ||
.stdout("Check your email to finish registering e2e\n"); | ||
.stdout("Check your email to finish registering e2e-first\n"); | ||
|
||
// Can start to register an entity twice as long as you don't | ||
// complete the process. | ||
Command::cargo_bin("ayb")? | ||
.args(["client", "register", "e2e", "[email protected]"]) | ||
.args(["client", "register", "e2e-first", "[email protected]"]) | ||
.env("AYB_SERVER_URL", server_url) | ||
.assert() | ||
.success() | ||
.stdout("Check your email to finish registering e2e\n"); | ||
.stdout("Check your email to finish registering e2e-first\n"); | ||
|
||
// Start the registration process for a second user (e2e-second) | ||
Command::cargo_bin("ayb")? | ||
.args([ | ||
"client", | ||
"register", | ||
"e2e-second", | ||
"[email protected]", | ||
]) | ||
.env("AYB_SERVER_URL", server_url) | ||
.assert() | ||
.success() | ||
.stdout("Check your email to finish registering e2e-second\n"); | ||
|
||
// Check that two emails were received | ||
let entries = utils::parse_smtp_log(&format!("tests/smtp_data_{}/[email protected]", smtp_port))?; | ||
assert_eq!(entries.len(), 2); | ||
let token0 = utils::extract_token(&entries[0])?; | ||
let token1 = utils::extract_token(&entries[1])?; | ||
let first_token0 = utils::extract_token(&entries[0])?; | ||
let first_token1 = utils::extract_token(&entries[1])?; | ||
let entries = utils::parse_smtp_log(&format!( | ||
"tests/smtp_data_{}/[email protected]", | ||
smtp_port | ||
))?; | ||
assert_eq!(entries.len(), 1); | ||
let token2 = utils::extract_token(&entries[0])?; | ||
assert_eq!(entries.len(), 2); | ||
let first_token2 = utils::extract_token(&entries[0])?; | ||
let second_token0 = utils::extract_token(&entries[1])?; | ||
|
||
// Using a bad token (appending a letter) doesn't work. | ||
Command::cargo_bin("ayb")? | ||
.args(["client", "confirm", &format!("{}a", token0)]) | ||
.args(["client", "confirm", &format!("{}a", first_token0)]) | ||
.env("AYB_SERVER_URL", server_url) | ||
.assert() | ||
.success() | ||
|
@@ -116,74 +130,134 @@ fn client_server_integration( | |
// third token, which was with a different email address for the | ||
// same account, won't work now that there's already a confirmed | ||
// email address on the account.. | ||
Command::cargo_bin("ayb")? | ||
.args(["client", "confirm", &token0]) | ||
.env("AYB_SERVER_URL", server_url) | ||
.assert() | ||
.success() | ||
.stdout("Successfully authenticated and saved token default/insecure, unimplemented\n"); | ||
let first_api_key0 = utils::extract_api_key( | ||
Command::cargo_bin("ayb")? | ||
.args(["client", "confirm", &first_token0]) | ||
.env("AYB_SERVER_URL", server_url) | ||
.assert() | ||
.success() | ||
.get_output(), | ||
)?; | ||
|
||
Command::cargo_bin("ayb")? | ||
.args(["client", "confirm", &token1]) | ||
.env("AYB_SERVER_URL", server_url) | ||
.assert() | ||
.success() | ||
.stdout("Successfully authenticated and saved token default/insecure, unimplemented\n"); | ||
let first_api_key1 = utils::extract_api_key( | ||
Command::cargo_bin("ayb")? | ||
.args(["client", "confirm", &first_token1]) | ||
.env("AYB_SERVER_URL", server_url) | ||
.assert() | ||
.success() | ||
.get_output(), | ||
)?; | ||
|
||
Command::cargo_bin("ayb")? | ||
.args(["client", "confirm", &token2]) | ||
.args(["client", "confirm", &first_token2]) | ||
.env("AYB_SERVER_URL", server_url) | ||
.assert() | ||
.success() | ||
.stdout("Error: e2e has already been registered\n"); | ||
.stdout("Error: e2e-first has already been registered\n"); | ||
|
||
// And for the second account, we can still confirm using the only | ||
// authentication token we've requested so far. | ||
let second_api_key0 = utils::extract_api_key( | ||
Command::cargo_bin("ayb")? | ||
.args(["client", "confirm", &second_token0]) | ||
.env("AYB_SERVER_URL", server_url) | ||
.assert() | ||
.success() | ||
.get_output(), | ||
)?; | ||
|
||
// Logging in as the user emails the first email address, which | ||
// can confirm using the token it received. | ||
Command::cargo_bin("ayb")? | ||
.args(["client", "log_in", "e2e"]) | ||
.args(["client", "log_in", "e2e-first"]) | ||
.env("AYB_SERVER_URL", server_url) | ||
.assert() | ||
.success() | ||
.stdout("Check your email to finish logging in e2e\n"); | ||
.stdout("Check your email to finish logging in e2e-first\n"); | ||
|
||
let entries = utils::parse_smtp_log(&format!("tests/smtp_data_{}/[email protected]", smtp_port))?; | ||
assert_eq!(entries.len(), 3); | ||
let login_token = utils::extract_token(&entries[2])?; | ||
let first_api_key2 = utils::extract_api_key( | ||
Command::cargo_bin("ayb")? | ||
.args(["client", "confirm", &login_token]) | ||
.env("AYB_SERVER_URL", server_url) | ||
.assert() | ||
.success() | ||
.get_output(), | ||
); | ||
|
||
// To summarize where we are at this point | ||
// * User e2e-first has three API tokens (first_api_key[0...2]). We'll use these | ||
// interchangeably below. | ||
// * User e2e-second has one API token (second_api_key0) | ||
|
||
// Can't create database on e2e-first with e2e-second's token. | ||
Command::cargo_bin("ayb")? | ||
.args(["client", "confirm", &login_token]) | ||
.env("AYB_SERVER_URL", server_url) | ||
.args([ | ||
"client", | ||
"--url", | ||
server_url, | ||
"create_database", | ||
"e2e-first/test.sqlite", | ||
"sqlite", | ||
]) | ||
.env("AYB_API_TOKEN", second_api_key0) | ||
.assert() | ||
.success() | ||
.stdout("Successfully authenticated and saved token default/insecure, unimplemented\n"); | ||
.stdout("Successfully created e2e/test.sqlite\n"); | ||
|
||
// Create database. | ||
// Can't create database on e2e-first with invalid token. | ||
Command::cargo_bin("ayb")? | ||
.args([ | ||
"client", | ||
"--url", | ||
server_url, | ||
"create_database", | ||
"e2e/test.sqlite", | ||
"e2e-first/test.sqlite", | ||
"sqlite", | ||
]) | ||
.env("AYB_API_TOKEN", format!("{}bad", first_api_key0.clone())) | ||
.assert() | ||
.success() | ||
.stdout("Successfully created e2e/test.sqlite\n"); | ||
|
||
// Create a database with the appropriate user/key pair. | ||
Command::cargo_bin("ayb")? | ||
.args([ | ||
"client", | ||
"--url", | ||
server_url, | ||
"create_database", | ||
"e2e-first/test.sqlite", | ||
"sqlite", | ||
]) | ||
.env("AYB_API_TOKEN", first_api_key0.clone()) | ||
.assert() | ||
.success() | ||
.stdout("Successfully created e2e-first/test.sqlite\n"); | ||
|
||
// Can't create a database twice. | ||
Command::cargo_bin("ayb")? | ||
.args([ | ||
"client", | ||
"--url", | ||
server_url, | ||
"create_database", | ||
"e2e/test.sqlite", | ||
"e2e-first/test.sqlite", | ||
"sqlite", | ||
]) | ||
.env("AYB_API_TOKEN", first_api_key0.clone()) | ||
.assert() | ||
.success() | ||
.stdout("Error: Database already exists\n"); | ||
|
||
// TODO | ||
// * Fix API token DB creation | ||
// * Query with other account's key (error) | ||
// * Query with invalid key (error) | ||
// * Query with the first account's three API keys (all work) | ||
|
||
// Populate and query database. | ||
client_query( | ||
server_url, | ||
|
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