@Test public void testContinueReadingAfterEOF() throws Exception { // vfs will return only "." and ".." as contents, both leading to itself List<DirectoryEntry> dirContents = new ArrayList<>(); dirContents.add(new DirectoryEntry(".", dirInode, dirStat)); dirContents.add(new DirectoryEntry("..", dirInode, dirStat)); Mockito.when(vfs.list(Mockito.eq(dirInode))).thenReturn(dirContents); // set up and execute the 1st call - no cookie, but very tight size limit RpcCall call = new RpcCallBuilder().from("1.2.3.4", "someHost.acme.com", 42).nfs3().noAuth().build(); READDIR3args args = NfsV3Ops.readDir(dirHandle); READDIR3res result = nfsServer.NFSPROC3_READDIR_3(call, args); Assert.assertEquals(nfsstat.NFS_OK, result.status); // response ok Assert.assertTrue(result.resok.reply.eof); // eof AssertXdr.assertXdrEncodable(result); // client violates spec - attempts to read more // using cookie on last (2nd) entry and returned verifier long cookie = result.resok.reply.entries.nextentry.cookie.value.value; byte[] cookieVerifier = result.resok.cookieverf.value; args = NfsV3Ops.readDir(dirHandle, cookie, cookieVerifier); result = nfsServer.NFSPROC3_READDIR_3(call, args); Assert.assertEquals(nfsstat.NFSERR_BAD_COOKIE, result.status); // error response AssertXdr.assertXdrEncodable(result); }
@Test public void testReadDirWithTinyLimit() throws Exception { // vfs will return only "." and ".." as contents, both leading to itself List<DirectoryEntry> dirContents = new ArrayList<>(); dirContents.add(new DirectoryEntry(".", dirInode, dirStat)); dirContents.add(new DirectoryEntry("..", dirInode, dirStat)); Mockito.when(vfs.list(Mockito.eq(dirInode))).thenReturn(dirContents); // set up and execute the 1st call - no cookie, but very tight size limit RpcCall call = new RpcCallBuilder().from("1.2.3.4", "someHost.acme.com", 42).nfs3().noAuth().build(); READDIR3args args = NfsV3Ops.readDir(dirHandle, 10); // 10 bytes - not enough for anything READDIR3res result = nfsServer.NFSPROC3_READDIR_3(call, args); Assert.assertEquals(nfsstat.NFSERR_TOOSMALL, result.status); // error response }
@Test public void testReadDirWithNoResults() throws Exception { // vfs will return an empty list from the vfs for dir (technically legal) Mockito.when(vfs.list(Mockito.eq(new Inode(dirHandle)))) .thenReturn(Collections.<DirectoryEntry>emptyList()); // set up and execute the call RpcCall call = new RpcCallBuilder().from("1.2.3.4", "someHost.acme.com", 42).nfs3().noAuth().build(); READDIR3args args = NfsV3Ops.readDir(dirHandle); READDIR3res result = nfsServer.NFSPROC3_READDIR_3(call, args); Assert.assertEquals(nfsstat.NFS_OK, result.status); Assert.assertNull(result.resok.reply.entries); // no entries Assert.assertTrue(result.resok.reply.eof); // eof AssertXdr.assertXdrEncodable(result); }