PseudoFs extends ForwardingFileSystem { @Override public Stat getattr(Inode inode) throws IOException { checkAccess(inode, ACE4_READ_ATTRIBUTES); return _inner.getattr(inode); } 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 public void testPrivilegedClient() throws IOException { InetSocketAddress privilegedClient = new InetSocketAddress(314); given(mockedTransport.getRemoteSocketAddress()).willReturn(privilegedClient); 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) .withPrivilegedClientPort() .build("/"); given(mockedExportFile.getExport(fsRoot.exportIndex(), privilegedClient.getAddress())).willReturn(export); pseudoFs = new PseudoFs(vfs, mockedRpc, mockedExportFile); pseudoFs.getattr(fsRoot); }
@Test(expected = PermException.class) public void testAuthFlavorTooWeak() 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.KRB5) .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.getattr(fsRoot); }
@Test public void testAuthFlavorMatch() throws IOException { RpcAuthGss mockedAuthGss = mock(RpcAuthGss.class); given(mockedTransport.getRemoteSocketAddress()).willReturn(localAddress); given(mockedAuthGss.getSubject()).willReturn(Subjects.ROOT); given(mockedAuthGss.type()).willReturn(RpcAuthType.RPCGSS_SEC); given(mockedAuthGss.getService()).willReturn(RpcGssService.RPC_GSS_SVC_NONE); given(mockedRpc.getTransport()).willReturn(mockedTransport); given(mockedRpc.getCredential()).willReturn(mockedAuthGss); FsExport export = new FsExport.FsExportBuilder() .rw() .trusted() .withoutAcl() .withSec(FsExport.Sec.KRB5) .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.getattr(fsRoot); }
@Test public void testAuthFlavorStrong() throws IOException { RpcAuthGss mockedAuthGss = mock(RpcAuthGss.class); given(mockedTransport.getRemoteSocketAddress()).willReturn(localAddress); given(mockedAuthGss.getSubject()).willReturn(Subjects.ROOT); given(mockedAuthGss.type()).willReturn(RpcAuthType.RPCGSS_SEC); given(mockedAuthGss.getService()).willReturn(RpcGssService.RPC_GSS_SVC_INTEGRITY); given(mockedRpc.getTransport()).willReturn(mockedTransport); given(mockedRpc.getCredential()).willReturn(mockedAuthGss); FsExport export = new FsExport.FsExportBuilder() .rw() .trusted() .withoutAcl() .withSec(FsExport.Sec.KRB5) .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.getattr(fsRoot); }
@Test(expected = AccessException.class) public void testAccessDenyOnHighjackedInode() throws IOException { given(mockedTransport.getRemoteSocketAddress()).willReturn(localAddress); given(mockedAuth.getSubject()).willReturn(Subjects.ROOT); given(mockedRpc.getTransport()).willReturn(mockedTransport); given(mockedRpc.getCredential()).willReturn(mockedAuth); Inode inode = new Inode( new FileHandle.FileHandleBuilder() .setExportIdx(1) .build(Longs.toByteArray(1L)) ); given(mockedExportFile.getExport(1, localAddress.getAddress())).willReturn(null); pseudoFs = new PseudoFs(vfs, mockedRpc, mockedExportFile); pseudoFs.getattr(inode); }
@Test(expected = AccessException.class) public void testUnprivilegedClient() 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) .withPrivilegedClientPort() .build("/"); given(mockedExportFile.getExport(fsRoot.exportIndex(), localAddress.getAddress())).willReturn(export); pseudoFs = new PseudoFs(vfs, mockedRpc, mockedExportFile); pseudoFs.getattr(fsRoot); }