-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Integration tests (#161) * Bumping smbj to 0.11.1 * Adding Bouncy Castle dep * Bump jdk target to 1.8 to align with smbj * Add integration tests for SRVSVC
- Loading branch information
Showing
13 changed files
with
335 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import com.rapid7.client.dcerpc.msrrp.RegistryService; | ||
import com.rapid7.client.dcerpc.mssrvs.ServerService; | ||
import com.rapid7.client.dcerpc.transport.RPCTransport; | ||
import com.rapid7.client.dcerpc.transport.SMBTransportFactories; | ||
import com.hierynomus.mssmb2.SMB2Dialect; | ||
import com.hierynomus.security.bc.BCSecurityProvider; | ||
import com.hierynomus.smbj.SMBClient; | ||
import com.hierynomus.smbj.SmbConfig; | ||
import com.hierynomus.smbj.auth.AuthenticationContext; | ||
import com.hierynomus.smbj.connection.Connection; | ||
import com.hierynomus.smbj.session.Session; | ||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.stream.Stream; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.EnumSource; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
import org.testcontainers.containers.GenericContainer; | ||
import org.testcontainers.images.builder.ImageFromDockerfile; | ||
import org.testcontainers.junit.jupiter.Container; | ||
import org.testcontainers.junit.jupiter.Testcontainers; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
@Testcontainers | ||
class IntegrationTestsIT | ||
{ | ||
private static final Path DOCKER_BUILD_CONTEXT = Paths.get("src", "integration-test", "resources", "docker-image"); | ||
|
||
@Container | ||
private static final GenericContainer<?> sambaContainer = new GenericContainer( | ||
new ImageFromDockerfile() | ||
.withFileFromPath(".", DOCKER_BUILD_CONTEXT)) | ||
.withExposedPorts(445); | ||
|
||
@ParameterizedTest | ||
@MethodSource("testWinRegDoesKeyExistForEachSupportedSMBVersionArgs") | ||
@DisplayName("Test registry service key exists function for different SMB protocols") | ||
void testWinRegDoesKeyExistForEachSupportedSMBVersion(String keyPath, boolean shouldExist, SMB2Dialect dialect) | ||
throws IOException | ||
{ | ||
final SmbConfig smbConfig = SmbConfig.builder().withSecurityProvider(new BCSecurityProvider()).withDialects(dialect).build(); | ||
final SMBClient smbClient = new SMBClient(smbConfig); | ||
try (final Connection smbConnection = smbClient.connect("localhost", sambaContainer.getMappedPort(445))) { | ||
final AuthenticationContext smbAuthenticationContext = new AuthenticationContext("smbj", "smbj".toCharArray(), ""); | ||
final Session session = smbConnection.authenticate(smbAuthenticationContext); | ||
|
||
final RPCTransport transport = SMBTransportFactories.WINREG.getTransport(session); | ||
final RegistryService registryService = new RegistryService(transport); | ||
|
||
assertEquals(dialect, smbConnection.getNegotiatedProtocol().getDialect()); | ||
assertEquals(shouldExist, registryService.doesKeyExist("HKLM", keyPath)); | ||
} | ||
} | ||
|
||
@ParameterizedTest | ||
@EnumSource(value = SMB2Dialect.class, names = {"SMB_2_0_2", "SMB_2_1", "SMB_3_0", "SMB_3_0_2", "SMB_3_1_1"}) | ||
@DisplayName("Test service service enumerates shares for different SMB protocols") | ||
void testSRVSVCReturnsSharesForEachSupportedSMBVersion(SMB2Dialect dialect) | ||
throws IOException | ||
{ | ||
final SmbConfig smbConfig = SmbConfig.builder().withSecurityProvider(new BCSecurityProvider()).withDialects(dialect).build(); | ||
final SMBClient smbClient = new SMBClient(smbConfig); | ||
try (final Connection smbConnection = smbClient.connect("localhost", sambaContainer.getMappedPort(445))) { | ||
final AuthenticationContext smbAuthenticationContext = new AuthenticationContext("smbj", "smbj".toCharArray(), ""); | ||
final Session session = smbConnection.authenticate(smbAuthenticationContext); | ||
|
||
final RPCTransport transport = SMBTransportFactories.SRVSVC.getTransport(session); | ||
final ServerService serverService = new ServerService(transport); | ||
|
||
assertEquals(dialect, smbConnection.getNegotiatedProtocol().getDialect()); | ||
assertEquals(5, serverService.getShares0().size()); | ||
} | ||
} | ||
|
||
static Stream<Arguments> testWinRegDoesKeyExistForEachSupportedSMBVersionArgs() { | ||
return Stream.of( | ||
Arguments.of("Software", true, SMB2Dialect.SMB_3_1_1), | ||
Arguments.of("not_exist", false, SMB2Dialect.SMB_3_1_1), | ||
Arguments.of("Software", true, SMB2Dialect.SMB_3_0_2), | ||
Arguments.of("not_exist", false, SMB2Dialect.SMB_3_0_2), | ||
Arguments.of("Software", true, SMB2Dialect.SMB_3_0), | ||
Arguments.of("not_exist", false, SMB2Dialect.SMB_3_0), | ||
Arguments.of("Software", true, SMB2Dialect.SMB_2_1), | ||
Arguments.of("not_exist", false, SMB2Dialect.SMB_2_1), | ||
Arguments.of("Software", true, SMB2Dialect.SMB_2_0_2), | ||
Arguments.of("not_exist", false, SMB2Dialect.SMB_2_0_2) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
FROM alpine:3.7 | ||
|
||
RUN apk update && apk add --no-cache tini samba samba-common-tools supervisor bash | ||
|
||
ENV SMB_USER smbj | ||
ENV SMB_PASSWORD smbj | ||
|
||
COPY smb.conf /etc/samba/smb.conf | ||
COPY supervisord.conf /etc/supervisord.conf | ||
COPY entrypoint.sh /entrypoint.sh | ||
ADD public /opt/samba/share | ||
|
||
RUN mkdir -p /opt/samba/readonly /opt/samba/user /opt/samba/dfs && \ | ||
chmod 777 /opt/samba/readonly /opt/samba/user /opt/samba/dfs && \ | ||
adduser -s /bin/false "$SMB_USER" -D $SMB_PASSWORD && \ | ||
(echo "$SMB_PASSWORD"; echo "$SMB_PASSWORD" ) | pdbedit -a -u "$SMB_USER" && \ | ||
chmod ugo+x /entrypoint.sh | ||
|
||
EXPOSE 137/udp 138/udp 139 445 | ||
|
||
ENTRYPOINT ["/sbin/tini", "/entrypoint.sh"] | ||
CMD ["supervisord"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
: "${SMB_USER:=smbuser}" | ||
: "${SMB_PASSWORD:=smbpassword}" | ||
# | ||
#for netdev in /sys/class/net/*; do | ||
# netdev=${netdev##*/} | ||
# if [[ "$netdev" != "lo" ]]; then | ||
# break | ||
# fi | ||
#done | ||
#subnet=$(ip addr show "$netdev" | sed -n 's/.*inet \([0-9\.]*\/[0-9]*\) .*/\1/p') | ||
#ip_address=${subnet%%/*} | ||
|
||
ip_address="127.0.0.1" | ||
|
||
# Create DFS links | ||
# - /public -> public share | ||
# - /user -> user share | ||
# - /firstfail-public -> first listed server fails, second -> public share | ||
ln -s "msdfs:${ip_address}\\public" /opt/samba/dfs/public | ||
ln -s "msdfs:${ip_address}\\user" /opt/samba/dfs/user | ||
ln -s "msdfs:192.0.2.1\\notthere,${ip_address}\\public" /opt/samba/dfs/firstfail-public | ||
|
||
exec "$@" |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Hi there! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
[global] | ||
security = user | ||
|
||
load printers = no | ||
printcap name = /dev/null | ||
printing = bsd | ||
|
||
unix charset = UTF-8 | ||
dos charset = CP932 | ||
|
||
workgroup = WORKGROUP | ||
|
||
server string = %h server (Samba, Ubuntu) | ||
dns proxy = no | ||
interfaces = 192.168.2.0/24 eth0 | ||
bind interfaces only = yes | ||
log file = /var/log/samba/log.%m | ||
max log size = 1000 | ||
syslog = 0 | ||
panic action = /usr/share/samba/panic-action %d | ||
server role = standalone server | ||
passdb backend = tdbsam | ||
obey pam restrictions = yes | ||
unix password sync = yes | ||
passwd program = /usr/bin/passwd %u | ||
passwd chat = *Enter\snew\s*\spassword:* %n\n *Retype\snew\s*\spassword:* %n\n *password\supdated\ssuccessfully* . | ||
pam password change = yes | ||
map to guest = Bad User | ||
usershare allow guests = yes | ||
host msdfs = yes | ||
|
||
[public] | ||
path = /opt/samba/share | ||
writable = yes | ||
printable = no | ||
public = yes | ||
guest only = yes | ||
create mode = 0777 | ||
directory mode = 0777 | ||
|
||
[readonly] | ||
path = /opt/samba/readonly | ||
writable = no | ||
printable = no | ||
public = no | ||
|
||
[user] | ||
path = /opt/samba/user | ||
writable = yes | ||
printable = no | ||
public = no | ||
create mode = 0777 | ||
directory mode = 0777 | ||
|
||
[dfs] | ||
path = /opt/samba/dfs | ||
writable = no | ||
printable = no | ||
public = yes | ||
guest ok = yes | ||
msdfs root = yes |
14 changes: 14 additions & 0 deletions
14
src/integration-test/resources/docker-image/supervisord.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[supervisord] | ||
nodaemon=true | ||
/* user=root */ | ||
loglevel=info | ||
|
||
[program:smbd] | ||
/* command=/usr/sbin/smbd -i --daemon --foreground --log-stdout */ | ||
command=/usr/sbin/smbd --daemon --foreground --log-stdout | ||
redirect_stderr=true | ||
|
||
[program:nmbd] | ||
/* command=/usr/sbin/nmbd -i --daemon --foreground --log-stdout */ | ||
command=/usr/sbin/nmbd --daemon --foreground --log-stdout | ||
redirect_stderr=true |
Oops, something went wrong.