2929import org .testcontainers .utility .MountableFile ;
3030
3131import java .io .IOException ;
32+ import java .nio .file .Files ;
33+ import java .nio .file .Path ;
34+ import java .nio .file .Paths ;
35+ import java .nio .file .attribute .PosixFilePermissions ;
3236import java .util .List ;
3337import java .util .concurrent .TimeUnit ;
3438
@@ -46,18 +50,29 @@ public class BanyanDBAuthTest {
4650 protected static final int HTTP_PORT = 17913 ;
4751
4852 @ Rule
49- public GenericContainer <?> banyanDB = new GenericContainer <>(DockerImageName .parse (IMAGE ))
50- .withCopyFileToContainer (
51- MountableFile .forClasspathResource ("config.yaml" ),
52- "/tmp/bydb_server_config.yaml"
53- )
54- .withCommand ("sh" , "-c" ,
55- "chmod 600 /tmp/bydb_server_config.yaml && exec standalone " +
56- "--auth-config-file /tmp/bydb_server_config.yaml " +
57- "--enable-health-auth false"
58- )
59- .withExposedPorts (GRPC_PORT , HTTP_PORT )
60- .waitingFor (Wait .forHttp ("/api/healthz" ).forPort (HTTP_PORT ));
53+ public GenericContainer <?> banyanDB ;
54+
55+ public BanyanDBAuthTest () throws Exception {
56+ // Step 1: prepare config file with 0600 permissions
57+ Path tempConfigPath = Files .createTempFile ("bydb_server_config" , ".yaml" );
58+ Files .write (tempConfigPath , Files .readAllBytes (
59+ Paths .get (getClass ().getClassLoader ().getResource ("config.yaml" ).toURI ()))
60+ );
61+ Files .setPosixFilePermissions (tempConfigPath , PosixFilePermissions .fromString ("rw-------" ));
62+
63+ // Step 2: create container
64+ banyanDB = new GenericContainer <>(DockerImageName .parse (IMAGE ))
65+ .withCopyFileToContainer (
66+ MountableFile .forHostPath (tempConfigPath ),
67+ "/tmp/bydb_server_config.yaml"
68+ )
69+ .withCommand ("standalone" ,
70+ "--auth-config-file" , "/tmp/bydb_server_config.yaml" ,
71+ "--enable-health-auth" , "false"
72+ )
73+ .withExposedPorts (GRPC_PORT , HTTP_PORT )
74+ .waitingFor (Wait .forHttp ("/api/healthz" ).forPort (HTTP_PORT ));
75+ }
6176
6277 @ Test
6378 public void testAuthWithCorrect () throws IOException {
0 commit comments