Skip to content

Commit d72a1ae

Browse files
committed
tests: add more tests for PseudoFs
Motivation: recent regression has shown that some test cases are not covered Modification: add explicit test for PseudoFs permission handling Result: better test coverage Acked-by: Dmitry Litvintsev Target: master
1 parent e4d041c commit d72a1ae

File tree

1 file changed

+104
-0
lines changed

1 file changed

+104
-0
lines changed

core/src/test/java/org/dcache/nfs/vfs/PseudoFsTest.java

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@
2828
import static org.mockito.Mockito.*;
2929

3030
import java.io.IOException;
31+
import java.net.InetAddress;
3132
import java.net.InetSocketAddress;
3233
import java.nio.charset.StandardCharsets;
3334
import java.util.stream.Stream;
3435

3536
import javax.security.auth.Subject;
3637

3738
import org.dcache.nfs.ExportFile;
39+
import org.dcache.nfs.ExportTable;
3840
import org.dcache.nfs.FsExport;
3941
import org.dcache.nfs.status.AccessException;
4042
import org.dcache.nfs.status.NoEntException;
@@ -743,4 +745,106 @@ public void testPrivilegedClient() throws IOException {
743745
pseudoFs = new PseudoFs(vfs, mockedRpc, mockedExportFile);
744746
pseudoFs.getattr(fsRoot);
745747
}
748+
749+
@Test
750+
public void testAllowListingByExportedClient() throws IOException {
751+
InetSocketAddress clientEndpoint = new InetSocketAddress("192.168.1.1", 314);
752+
753+
Subject subject = toSubject(17, 17);
754+
Inode parent = vfs.mkdir(fsRoot, "exports", subject, 0755);
755+
vfs.mkdir(parent, "data", subject, 0755);
756+
757+
given(mockedTransport.getRemoteSocketAddress()).willReturn(clientEndpoint);
758+
given(mockedAuth.getSubject()).willReturn(ROOT);
759+
given(mockedAuth.type()).willReturn(RpcAuthType.UNIX);
760+
given(mockedRpc.getTransport()).willReturn(mockedTransport);
761+
given(mockedRpc.getCredential()).willReturn(mockedAuth);
762+
763+
FsExport export1 = new FsExport.FsExportBuilder()
764+
.rw()
765+
.trusted()
766+
.withoutAcl()
767+
.withSec(FsExport.Sec.SYS)
768+
.forClient("192.168.1.0/24")
769+
.build("/exports/data");
770+
771+
772+
var exportTable = new ExportTable() {
773+
774+
@Override
775+
public Stream<FsExport> exports() {
776+
throw new RuntimeException("not used in this test");
777+
}
778+
779+
@Override
780+
public Stream<FsExport> exports(InetAddress client) {
781+
return export1.isAllowed(client) ? Stream.of(export1) : Stream.empty();
782+
}
783+
784+
@Override
785+
public FsExport getExport(String path, InetAddress client) {
786+
return export1.getPath().equals(path) && export1.isAllowed(client)? export1 : null;
787+
}
788+
789+
@Override
790+
public FsExport getExport(int index, InetAddress client) {
791+
return export1.getIndex() == index && export1.isAllowed(client) ? export1 : null;
792+
}
793+
};
794+
795+
pseudoFs = new PseudoFs(vfs, mockedRpc, exportTable);
796+
Inode pseudoRoot = pseudoFs.getRootInode();
797+
pseudoFs.list(pseudoRoot, DirectoryStream.ZERO_VERIFIER, 0);
798+
}
799+
800+
801+
@Test(expected = AccessException.class)
802+
public void testRejectListing() throws IOException {
803+
InetSocketAddress clientEndpoint = new InetSocketAddress("192.168.2.1", 314);
804+
805+
Subject subject = toSubject(17, 17);
806+
Inode parent = vfs.mkdir(fsRoot, "exports", subject, 0755);
807+
vfs.mkdir(parent, "data", subject, 0755);
808+
809+
given(mockedTransport.getRemoteSocketAddress()).willReturn(clientEndpoint);
810+
given(mockedAuth.getSubject()).willReturn(ROOT);
811+
given(mockedAuth.type()).willReturn(RpcAuthType.UNIX);
812+
given(mockedRpc.getTransport()).willReturn(mockedTransport);
813+
given(mockedRpc.getCredential()).willReturn(mockedAuth);
814+
815+
FsExport export1 = new FsExport.FsExportBuilder()
816+
.rw()
817+
.trusted()
818+
.withoutAcl()
819+
.withSec(FsExport.Sec.SYS)
820+
.forClient("192.168.1.0/24")
821+
.build("/exports/data");
822+
823+
var exportTable = new ExportTable() {
824+
825+
@Override
826+
public Stream<FsExport> exports() {
827+
throw new RuntimeException("not used in this test");
828+
}
829+
830+
@Override
831+
public Stream<FsExport> exports(InetAddress client) {
832+
return export1.isAllowed(client) ? Stream.of(export1) : Stream.empty();
833+
}
834+
835+
@Override
836+
public FsExport getExport(String path, InetAddress client) {
837+
return export1.getPath().equals(path) && export1.isAllowed(client)? export1 : null;
838+
}
839+
840+
@Override
841+
public FsExport getExport(int index, InetAddress client) {
842+
return export1.getIndex() == index && export1.isAllowed(client) ? export1 : null;
843+
}
844+
};
845+
846+
pseudoFs = new PseudoFs(vfs, mockedRpc, exportTable);
847+
Inode pseudoRoot = pseudoFs.getRootInode();
848+
pseudoFs.list(pseudoRoot, DirectoryStream.ZERO_VERIFIER, 0);
849+
}
746850
}

0 commit comments

Comments
 (0)