Skip to content

Commit

Permalink
fix(mssql)!: make EULA acception explicit (#218)
Browse files Browse the repository at this point in the history
- EULA: I've noticed the default, while it's necessary to do explicitly.
Separate method has been added (might be explicit
- Make default password publicly available
  • Loading branch information
DDtKey authored Sep 25, 2024
1 parent ebf549f commit 1c29a89
Showing 1 changed file with 25 additions and 16 deletions.
41 changes: 25 additions & 16 deletions src/mssql_server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use testcontainers::{core::WaitFor, Image};
/// ```
/// use testcontainers_modules::{testcontainers::runners::SyncRunner, mssql_server};
///
/// let mssql_server = mssql_server::MssqlServer::default().start().unwrap();
/// let mssql_server = mssql_server::MssqlServer::default().with_accept_eula().start().unwrap();
/// let ado_connection_string = format!(
/// "Server=tcp:{},{};Database=test;User Id=sa;Password=yourStrong(!)Password;TrustServerCertificate=True;",
/// mssql_server.get_host().unwrap(),
Expand All @@ -33,12 +33,12 @@ use testcontainers::{core::WaitFor, Image};
/// Following environment variables are required.
/// A image provided by this module has default values for them.
///
/// ## `ACCEPT_EULA`
/// ## EULA Acceptance
///
/// You need to accept the [End-User Licensing Agreement](https://go.microsoft.com/fwlink/?linkid=857698)
/// before using the SQL Server image provided by this module.
/// To accept EULA, you can set this environment variable to `Y`.
/// The default value is `Y`.
/// Due to licensing restrictions you are required to explicitly accept an End User License Agreement (EULA) for the MS SQL Server container image.
/// This is facilitated through the explicit call of `with_accept_eula` function.
///
/// Please see the [microsoft-mssql-server image documentation](https://hub.docker.com/_/microsoft-mssql-server#environment-variables) for a link to the EULA document.
///
/// ## `MSSQL_SA_PASSWORD`
///
Expand All @@ -58,21 +58,28 @@ pub struct MssqlServer {
impl MssqlServer {
const NAME: &'static str = "mcr.microsoft.com/mssql/server";
const TAG: &'static str = "2022-CU14-ubuntu-22.04";
const DEFAULT_SA_PASSWORD: &'static str = "yourStrong(!)Password";
pub const DEFAULT_SA_PASSWORD: &'static str = "yourStrong(!)Password";

/// Sets the password as `MSSQL_SA_PASSWORD`.
pub fn with_sa_password(self, password: impl Into<String>) -> Self {
let mut env_vars = self.env_vars;
env_vars.insert("MSSQL_SA_PASSWORD".to_owned(), password.into());
pub fn with_sa_password(mut self, password: impl Into<String>) -> Self {
self.env_vars
.insert("MSSQL_SA_PASSWORD".into(), password.into());
self
}

Self { env_vars }
/// Due to licensing restrictions you are required to explicitly accept an End User License Agreement (EULA) for the MS SQL Server container image.
/// This is facilitated through the `with_accept_eula` function.
///
/// Please see the [microsoft-mssql-server image documentation](https://hub.docker.com/_/microsoft-mssql-server#environment-variables) for a link to the EULA document.
pub fn with_accept_eula(mut self) -> Self {
self.env_vars.insert("ACCEPT_EULA".into(), "Y".into());
self
}
}

impl Default for MssqlServer {
fn default() -> Self {
let mut env_vars = HashMap::new();
env_vars.insert("ACCEPT_EULA".to_owned(), "Y".to_owned());
env_vars.insert(
"MSSQL_SA_PASSWORD".to_owned(),
Self::DEFAULT_SA_PASSWORD.to_owned(),
Expand Down Expand Up @@ -120,11 +127,11 @@ mod tests {

#[tokio::test]
async fn one_plus_one() -> Result<(), Box<dyn error::Error>> {
let container = MssqlServer::default().start().await?;
let container = MssqlServer::default().with_accept_eula().start().await?;
let config = new_config(
container.get_host().await?,
container.get_host_port_ipv4(1433).await?,
"yourStrong(!)Password",
"Strong@Passw0rd",
);
let mut client = get_mssql_client(config).await?;

Expand All @@ -138,12 +145,14 @@ mod tests {

#[tokio::test]
async fn custom_sa_password() -> Result<(), Box<dyn error::Error>> {
let image = MssqlServer::default().with_sa_password("yourStrongPassword123!");
let image = MssqlServer::default()
.with_accept_eula()
.with_sa_password("yourStrongPassword123!");
let container = image.start().await?;
let config = new_config(
container.get_host().await?,
container.get_host_port_ipv4(1433).await?,
"yourStrongPassword123!",
MssqlServer::DEFAULT_SA_PASSWORD,
);
let mut client = get_mssql_client(config).await?;

Expand Down

0 comments on commit 1c29a89

Please sign in to comment.