PseudoFs extends ForwardingFileSystem { @Override public Inode create(Inode parent, Stat.Type type, String path, Subject subject, int mode) throws IOException { Subject effectiveSubject = checkAccess(parent, ACE4_ADD_FILE); if (subject != null && Subjects.isRoot(effectiveSubject)) { effectiveSubject = subject; } if (inheritUidGid(parent)) { Stat s = _inner.getattr(parent); effectiveSubject = Subjects.of(s.getUid(), s.getGid()); } return pushExportIndex(parent, _inner.create(parent, type, path, effectiveSubject, mode)); } PseudoFs(VirtualFileSystem inner, RpcCall call, ExportTable exportTable); @Override int access(Inode inode, int mode); @Override Inode create(Inode parent, Stat.Type type, String path, Subject subject, int mode); @Override Inode getRootInode(); @Override Inode lookup(Inode parent, String path); @Override Inode link(Inode parent, Inode link, String path, Subject subject); @Override DirectoryStream list(Inode inode, byte[] verifier, long cookie); @Override Inode mkdir(Inode parent, String path, Subject subject, int mode); @Override boolean move(Inode src, String oldName, Inode dest, String newName); @Override Inode parentOf(Inode inode); @Override int read(Inode inode, byte[] data, long offset, int count); @Override int read(Inode inode, ByteBuffer data, long offset); @Override String readlink(Inode inode); @Override void remove(Inode parent, String path); @Override Inode symlink(Inode parent, String path, String link, Subject subject, int mode); @Override WriteResult write(Inode inode, byte[] data, long offset, int count, StabilityLevel stabilityLevel); @Override WriteResult write(Inode inode, ByteBuffer data, long offset, StabilityLevel stabilityLevel); @Override Stat getattr(Inode inode); @Override void setattr(Inode inode, Stat stat); @Override nfsace4[] getAcl(Inode inode); @Override void setAcl(Inode inode, nfsace4[] acl); @Override byte[] getXattr(Inode inode, String attr); @Override void setXattr(Inode inode, String attr, byte[] value, SetXattrMode mode); @Override String[] listXattrs(Inode inode); @Override void removeXattr(Inode inode, String attr); static Inode pseudoIdToReal(Inode inode, int index); static final int PRIVILEGED_PORT; }
@Test(expected = AccessException.class) public void testRootSquash() throws IOException { given(mockedTransport.getRemoteSocketAddress()).willReturn(localAddress); given(mockedAuth.getSubject()).willReturn(Subjects.ROOT); given(mockedRpc.getTransport()).willReturn(mockedTransport); given(mockedRpc.getCredential()).willReturn(mockedAuth); FsExport export = new FsExport.FsExportBuilder() .rw() .notTrusted() .withoutAcl() .withSec(FsExport.Sec.NONE) .build("/"); given(mockedExportFile.getExport(fsRoot.exportIndex(), localAddress.getAddress())).willReturn(export); given(mockedExportFile.exports(localAddress.getAddress())).willReturn(Stream.of(export)); pseudoFs = new PseudoFs(vfs, mockedRpc, mockedExportFile); pseudoFs.create(fsRoot, Stat.Type.REGULAR, "aFile", Subjects.ROOT, 0644); }
@Test public void testNoRootSquash() throws IOException { given(mockedTransport.getRemoteSocketAddress()).willReturn(localAddress); given(mockedAuth.getSubject()).willReturn(Subjects.ROOT); given(mockedRpc.getTransport()).willReturn(mockedTransport); given(mockedRpc.getCredential()).willReturn(mockedAuth); FsExport export = new FsExport.FsExportBuilder() .rw() .trusted() .withoutAcl() .withSec(FsExport.Sec.NONE) .build("/"); given(mockedExportFile.getExport(fsRoot.exportIndex(), localAddress.getAddress())).willReturn(export); given(mockedExportFile.exports(localAddress.getAddress())).willReturn(Stream.of(export)); pseudoFs = new PseudoFs(vfs, mockedRpc, mockedExportFile); pseudoFs.create(fsRoot, Stat.Type.REGULAR, "aFile", Subjects.ROOT, 0644); }
@Test(expected = AccessException.class) public void testAllSquash() throws IOException { given(mockedTransport.getRemoteSocketAddress()).willReturn(localAddress); given(mockedAuth.getSubject()).willReturn(Subjects.of(1, 1)); given(mockedRpc.getTransport()).willReturn(mockedTransport); given(mockedRpc.getCredential()).willReturn(mockedAuth); given(mockedExport.ioMode()).willReturn(FsExport.IO.RW); given(mockedExport.isTrusted()).willReturn(true); given(mockedExport.checkAcls()).willReturn(false); given(mockedExport.hasAllSquash()).willReturn(true); given(mockedExport.getSec()).willReturn(FsExport.Sec.NONE); FsExport export = new FsExport.FsExportBuilder() .rw() .trusted() .allSquash() .withoutAcl() .withSec(FsExport.Sec.NONE) .build("/"); given(mockedExportFile.getExport(fsRoot.exportIndex(), localAddress.getAddress())).willReturn(export); given(mockedExportFile.exports(localAddress.getAddress())).willReturn(Stream.of(export)); pseudoFs = new PseudoFs(vfs, mockedRpc, mockedExportFile); pseudoFs.create(fsRoot, Stat.Type.REGULAR, "aFile", Subjects.ROOT, 0644); }