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

Commit 7429dec

Browse filesBrowse files
Merge pull request theseus-rs#64 from theseus-rs/add-auth-tests
add auth tests
2 parents 9ca4227 + d63d6bf commit 7429dec
Copy full SHA for 7429dec

File tree

Expand file treeCollapse file tree

3 files changed

+75
-16
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+75
-16
lines changed

‎Cargo.lock

Copy file name to clipboardExpand all lines: Cargo.lock
+19-12Lines changed: 19 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎postgresql_embedded/src/postgresql.rs

Copy file name to clipboardExpand all lines: postgresql_embedded/src/postgresql.rs
-2Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,6 @@ impl PostgreSQL {
338338
self.settings.port
339339
);
340340
let psql = PsqlBuilder::from(&self.settings)
341-
.program_dir(self.settings.binary_dir())
342341
.command(format!(
343342
"SELECT 1 FROM pg_database WHERE datname='{}'",
344343
database_name.as_ref()
@@ -366,7 +365,6 @@ impl PostgreSQL {
366365
self.settings.port
367366
);
368367
let psql = PsqlBuilder::from(&self.settings)
369-
.program_dir(self.settings.binary_dir())
370368
.command(format!(
371369
"DROP DATABASE IF EXISTS \"{}\"",
372370
database_name.as_ref()

‎postgresql_embedded/tests/postgresql.rs

Copy file name to clipboardExpand all lines: postgresql_embedded/tests/postgresql.rs
+56-2Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use anyhow::bail;
22
use postgresql_archive::LATEST;
3+
use postgresql_commands::psql::PsqlBuilder;
4+
use postgresql_commands::CommandBuilder;
35
use postgresql_embedded::{PostgreSQL, Result, Settings, Status};
46
use std::fs::{remove_dir_all, remove_file};
57
use test_log::test;
@@ -144,11 +146,63 @@ async fn postgres_concurrency() -> anyhow::Result<()> {
144146
Ok(())
145147
}
146148

149+
#[test(tokio::test)]
150+
async fn test_authentication_success() -> Result<()> {
151+
let mut postgresql = PostgreSQL::default();
152+
postgresql.setup().await?;
153+
postgresql.start().await?;
154+
155+
let mut psql = PsqlBuilder::from(postgresql.settings())
156+
.command("SELECT 1")
157+
.no_psqlrc()
158+
.tuples_only()
159+
.build();
160+
161+
let output = psql.output()?;
162+
assert!(output.status.success());
163+
Ok(())
164+
}
165+
166+
#[test(tokio::test)]
167+
async fn test_authentication_invalid_username() -> Result<()> {
168+
let mut postgresql = PostgreSQL::default();
169+
postgresql.setup().await?;
170+
postgresql.start().await?;
171+
172+
let mut psql = PsqlBuilder::from(postgresql.settings())
173+
.command("SELECT 1")
174+
.username("invalid")
175+
.no_psqlrc()
176+
.tuples_only()
177+
.build();
178+
179+
let output = psql.output()?;
180+
assert!(!output.status.success());
181+
Ok(())
182+
}
183+
184+
#[test(tokio::test)]
185+
async fn test_authentication_invalid_password() -> Result<()> {
186+
let mut postgresql = PostgreSQL::default();
187+
postgresql.setup().await?;
188+
postgresql.start().await?;
189+
190+
let mut psql = PsqlBuilder::from(postgresql.settings())
191+
.command("SELECT 1")
192+
.pg_password("invalid")
193+
.no_psqlrc()
194+
.tuples_only()
195+
.build();
196+
197+
let output = psql.output()?;
198+
assert!(!output.status.success());
199+
Ok(())
200+
}
201+
147202
#[test(tokio::test)]
148203
async fn test_username_setting() -> Result<()> {
149-
let username = "admin".to_string();
150204
let settings = Settings {
151-
username,
205+
username: "admin".to_string(),
152206
..Default::default()
153207
};
154208
let mut postgresql = PostgreSQL::new(LATEST, settings);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.