Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

add auth tests #64

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 19 additions & 12 deletions 31 Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions 2 postgresql_embedded/src/postgresql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,6 @@ impl PostgreSQL {
self.settings.port
);
let psql = PsqlBuilder::from(&self.settings)
.program_dir(self.settings.binary_dir())
.command(format!(
"SELECT 1 FROM pg_database WHERE datname='{}'",
database_name.as_ref()
Expand Down Expand Up @@ -366,7 +365,6 @@ impl PostgreSQL {
self.settings.port
);
let psql = PsqlBuilder::from(&self.settings)
.program_dir(self.settings.binary_dir())
.command(format!(
"DROP DATABASE IF EXISTS \"{}\"",
database_name.as_ref()
Expand Down
58 changes: 56 additions & 2 deletions 58 postgresql_embedded/tests/postgresql.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use anyhow::bail;
use postgresql_archive::LATEST;
use postgresql_commands::psql::PsqlBuilder;
use postgresql_commands::CommandBuilder;
use postgresql_embedded::{PostgreSQL, Result, Settings, Status};
use std::fs::{remove_dir_all, remove_file};
use test_log::test;
Expand Down Expand Up @@ -144,11 +146,63 @@ async fn postgres_concurrency() -> anyhow::Result<()> {
Ok(())
}

#[test(tokio::test)]
async fn test_authentication_success() -> Result<()> {
let mut postgresql = PostgreSQL::default();
postgresql.setup().await?;
postgresql.start().await?;

let mut psql = PsqlBuilder::from(postgresql.settings())
.command("SELECT 1")
.no_psqlrc()
.tuples_only()
.build();

let output = psql.output()?;
assert!(output.status.success());
Ok(())
}

#[test(tokio::test)]
async fn test_authentication_invalid_username() -> Result<()> {
let mut postgresql = PostgreSQL::default();
postgresql.setup().await?;
postgresql.start().await?;

let mut psql = PsqlBuilder::from(postgresql.settings())
.command("SELECT 1")
.username("invalid")
.no_psqlrc()
.tuples_only()
.build();

let output = psql.output()?;
assert!(!output.status.success());
Ok(())
}

#[test(tokio::test)]
async fn test_authentication_invalid_password() -> Result<()> {
let mut postgresql = PostgreSQL::default();
postgresql.setup().await?;
postgresql.start().await?;

let mut psql = PsqlBuilder::from(postgresql.settings())
.command("SELECT 1")
.pg_password("invalid")
.no_psqlrc()
.tuples_only()
.build();

let output = psql.output()?;
assert!(!output.status.success());
Ok(())
}

#[test(tokio::test)]
async fn test_username_setting() -> Result<()> {
let username = "admin".to_string();
let settings = Settings {
username,
username: "admin".to_string(),
..Default::default()
};
let mut postgresql = PostgreSQL::new(LATEST, settings);
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.