Skip to content

Commit 1c29a89

Browse files
authored
fix(mssql)!: make EULA acception explicit (#218)
- 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
1 parent ebf549f commit 1c29a89

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed

src/mssql_server/mod.rs

+25-16
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use testcontainers::{core::WaitFor, Image};
1717
/// ```
1818
/// use testcontainers_modules::{testcontainers::runners::SyncRunner, mssql_server};
1919
///
20-
/// let mssql_server = mssql_server::MssqlServer::default().start().unwrap();
20+
/// let mssql_server = mssql_server::MssqlServer::default().with_accept_eula().start().unwrap();
2121
/// let ado_connection_string = format!(
2222
/// "Server=tcp:{},{};Database=test;User Id=sa;Password=yourStrong(!)Password;TrustServerCertificate=True;",
2323
/// mssql_server.get_host().unwrap(),
@@ -33,12 +33,12 @@ use testcontainers::{core::WaitFor, Image};
3333
/// Following environment variables are required.
3434
/// A image provided by this module has default values for them.
3535
///
36-
/// ## `ACCEPT_EULA`
36+
/// ## EULA Acceptance
3737
///
38-
/// You need to accept the [End-User Licensing Agreement](https://go.microsoft.com/fwlink/?linkid=857698)
39-
/// before using the SQL Server image provided by this module.
40-
/// To accept EULA, you can set this environment variable to `Y`.
41-
/// The default value is `Y`.
38+
/// Due to licensing restrictions you are required to explicitly accept an End User License Agreement (EULA) for the MS SQL Server container image.
39+
/// This is facilitated through the explicit call of `with_accept_eula` function.
40+
///
41+
/// Please see the [microsoft-mssql-server image documentation](https://hub.docker.com/_/microsoft-mssql-server#environment-variables) for a link to the EULA document.
4242
///
4343
/// ## `MSSQL_SA_PASSWORD`
4444
///
@@ -58,21 +58,28 @@ pub struct MssqlServer {
5858
impl MssqlServer {
5959
const NAME: &'static str = "mcr.microsoft.com/mssql/server";
6060
const TAG: &'static str = "2022-CU14-ubuntu-22.04";
61-
const DEFAULT_SA_PASSWORD: &'static str = "yourStrong(!)Password";
61+
pub const DEFAULT_SA_PASSWORD: &'static str = "yourStrong(!)Password";
6262

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

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

7280
impl Default for MssqlServer {
7381
fn default() -> Self {
7482
let mut env_vars = HashMap::new();
75-
env_vars.insert("ACCEPT_EULA".to_owned(), "Y".to_owned());
7683
env_vars.insert(
7784
"MSSQL_SA_PASSWORD".to_owned(),
7885
Self::DEFAULT_SA_PASSWORD.to_owned(),
@@ -120,11 +127,11 @@ mod tests {
120127

121128
#[tokio::test]
122129
async fn one_plus_one() -> Result<(), Box<dyn error::Error>> {
123-
let container = MssqlServer::default().start().await?;
130+
let container = MssqlServer::default().with_accept_eula().start().await?;
124131
let config = new_config(
125132
container.get_host().await?,
126133
container.get_host_port_ipv4(1433).await?,
127-
"yourStrong(!)Password",
134+
"Strong@Passw0rd",
128135
);
129136
let mut client = get_mssql_client(config).await?;
130137

@@ -138,12 +145,14 @@ mod tests {
138145

139146
#[tokio::test]
140147
async fn custom_sa_password() -> Result<(), Box<dyn error::Error>> {
141-
let image = MssqlServer::default().with_sa_password("yourStrongPassword123!");
148+
let image = MssqlServer::default()
149+
.with_accept_eula()
150+
.with_sa_password("yourStrongPassword123!");
142151
let container = image.start().await?;
143152
let config = new_config(
144153
container.get_host().await?,
145154
container.get_host_port_ipv4(1433).await?,
146-
"yourStrongPassword123!",
155+
MssqlServer::DEFAULT_SA_PASSWORD,
147156
);
148157
let mut client = get_mssql_client(config).await?;
149158

0 commit comments

Comments
 (0)