Skip to content

Commit e43ba5c

Browse files
committed
core: test: Fix NfsServerV3READDIR_3Test, NfsServerV3READDIRPLUS_3Test
These two tests heavily use mock code and directly interact with NFS internals. With the combination of FileHandle and Inode, a discrepancy of expected NFS handles was uncovered -- the NFS handle shown to clients has an exportId of 1 (via PseudoFS), whereas the underlying handle does not. This now creates a test error because these two Inodes are different, and mocking code only returns a value for an exact sequence of bytes. Change the test such that all calls to NfsServerV3.NFSPROC3_READDIR* use the public-facing Inode (with exportId 1), and all the other code the underlying inode (with exportId=0/unset). Related: #149 Signed-off-by: Christian Kohlschütter <[email protected]>
1 parent da99d7f commit e43ba5c

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

core/src/test/java/org/dcache/nfs/v3/NfsServerV3READDIRPLUS_3Test.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,15 @@
3434

3535
public class NfsServerV3READDIRPLUS_3Test {
3636
private Inode dirInode;
37+
private Inode dirInodePseudoFS;
3738
private Stat dirStat;
3839
private VirtualFileSystem vfs;
3940
private NfsServerV3 nfsServer;
4041

4142
@Before
4243
public void setup() throws Exception {
43-
dirInode = new Inode(0, 1, 0, new byte[] {0, 0, 0, 1}); // the dir we want to read;
44+
dirInode = Inode.forFile(new byte[] {0, 0, 0, 1}); // the dir we want to read;
45+
dirInodePseudoFS = new Inode(0, 1, 0, new byte[] {0, 0, 0, 1}); // the handle as seen from the outside
4446
dirStat = new Stat(); // the stat marking it as a dir
4547
// noinspection OctalInteger
4648
dirStat.setMode(Stat.S_IFDIR | 0755);
@@ -72,7 +74,7 @@ public void testReadDirWithNoResults() throws Exception {
7274

7375
// set up and execute the call
7476
RpcCall call = new RpcCallBuilder().from("1.2.3.4", "someHost.acme.com", 42).nfs3().noAuth().build();
75-
READDIRPLUS3args args = NfsV3Ops.readDirPlus(dirInode);
77+
READDIRPLUS3args args = NfsV3Ops.readDirPlus(dirInodePseudoFS);
7678
READDIRPLUS3res result = nfsServer.NFSPROC3_READDIRPLUS_3(call, args);
7779

7880
Assert.assertEquals(nfsstat.NFS_OK, result.status);
@@ -94,7 +96,7 @@ public void testReadDirWithTinyLimit() throws Exception {
9496

9597
// set up and execute the 1st call - no cookie, but very tight size limit
9698
RpcCall call = new RpcCallBuilder().from("1.2.3.4", "someHost.acme.com", 42).nfs3().noAuth().build();
97-
READDIRPLUS3args args = NfsV3Ops.readDirPlus(dirInode, 10); // 10 bytes - not enough for anything
99+
READDIRPLUS3args args = NfsV3Ops.readDirPlus(dirInodePseudoFS, 10); // 10 bytes - not enough for anything
98100
READDIRPLUS3res result = nfsServer.NFSPROC3_READDIRPLUS_3(call, args);
99101

100102
Assert.assertEquals(nfsstat.NFSERR_TOOSMALL, result.status); // error response
@@ -113,7 +115,7 @@ public void testContinueReadingAfterEOF() throws Exception {
113115

114116
// set up and execute the 1st call - no cookie, but very tight size limit
115117
RpcCall call = new RpcCallBuilder().from("1.2.3.4", "someHost.acme.com", 42).nfs3().noAuth().build();
116-
READDIRPLUS3args args = NfsV3Ops.readDirPlus(dirInode);
118+
READDIRPLUS3args args = NfsV3Ops.readDirPlus(dirInodePseudoFS);
117119
READDIRPLUS3res result = nfsServer.NFSPROC3_READDIRPLUS_3(call, args);
118120

119121
Assert.assertEquals(nfsstat.NFS_OK, result.status); // response ok
@@ -123,7 +125,7 @@ public void testContinueReadingAfterEOF() throws Exception {
123125
// re-read after EOF
124126
long cookie = result.resok.reply.entries.nextentry.cookie.value.value;
125127
cookieVerifier = result.resok.cookieverf.value;
126-
args = NfsV3Ops.readDirPlus(dirInode, cookie, cookieVerifier);
128+
args = NfsV3Ops.readDirPlus(dirInodePseudoFS, cookie, cookieVerifier);
127129
result = nfsServer.NFSPROC3_READDIRPLUS_3(call, args);
128130

129131
Assert.assertEquals(nfsstat.NFS_OK, result.status); // response ok
@@ -146,7 +148,7 @@ public void testSemiValidVerifier() throws Exception {
146148
long cookie = 1;
147149

148150
RpcCall call = new RpcCallBuilder().from("1.2.3.4", "someHost.acme.com", 42).nfs3().noAuth().build();
149-
READDIRPLUS3args args = NfsV3Ops.readDirPlus(dirInode, cookie, cookieVerifier);
151+
READDIRPLUS3args args = NfsV3Ops.readDirPlus(dirInodePseudoFS, cookie, cookieVerifier);
150152
READDIRPLUS3res result = nfsServer.NFSPROC3_READDIRPLUS_3(call, args);
151153

152154
Assert.assertEquals(nfsstat.NFS_OK, result.status); // error response
@@ -170,7 +172,7 @@ public void testEofIfLastEntryDoesNotFit() throws Exception {
170172
when(vfs.list(eq(dirInode), any(), anyLong())).thenReturn(new DirectoryStream(cookieVerifier, dirContents));
171173

172174
RpcCall call = new RpcCallBuilder().from("1.2.3.4", "someHost.acme.com", 42).nfs3().noAuth().build();
173-
READDIRPLUS3args args = NfsV3Ops.readDirPlus(dirInode, 0, cookieVerifier, 3480, 1024); // only 22 entries will
175+
READDIRPLUS3args args = NfsV3Ops.readDirPlus(dirInodePseudoFS, 0, cookieVerifier, 3480, 1024); // only 22 entries will
174176
// fit
175177
READDIRPLUS3res result = nfsServer.NFSPROC3_READDIRPLUS_3(call, args);
176178

core/src/test/java/org/dcache/nfs/v3/NfsServerV3READDIR_3Test.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,15 @@
3535
public class NfsServerV3READDIR_3Test {
3636

3737
private Inode dirInode;
38+
private Inode dirInodePseudoFS;
3839
private Stat dirStat;
3940
private VirtualFileSystem vfs;
4041
private NfsServerV3 nfsServer;
4142

4243
@Before
4344
public void setup() throws Exception {
44-
dirInode = new Inode(0, 1, 0, new byte[] {0, 0, 0, 1}); // the dir we want to read
45+
dirInode = Inode.forFile(new byte[] {0, 0, 0, 1}); // the dir we want to read;
46+
dirInodePseudoFS = new Inode(0, 1, 0, new byte[] {0, 0, 0, 1}); // the handle as seen from the outside
4547
dirStat = new Stat(); // the stat marking it as a dir
4648
// noinspection OctalInteger
4749
dirStat.setMode(Stat.S_IFDIR | 0755);
@@ -73,7 +75,7 @@ public void testReadDirWithNoResults() throws Exception {
7375

7476
// set up and execute the call
7577
RpcCall call = new RpcCallBuilder().from("1.2.3.4", "someHost.acme.com", 42).nfs3().noAuth().build();
76-
READDIR3args args = NfsV3Ops.readDir(dirInode);
78+
READDIR3args args = NfsV3Ops.readDir(dirInodePseudoFS);
7779
READDIR3res result = nfsServer.NFSPROC3_READDIR_3(call, args);
7880

7981
Assert.assertEquals(nfsstat.NFS_OK, result.status);
@@ -93,7 +95,7 @@ public void testReadDirWithTinyLimit() throws Exception {
9395

9496
// set up and execute the 1st call - no cookie, but very tight size limit
9597
RpcCall call = new RpcCallBuilder().from("1.2.3.4", "someHost.acme.com", 42).nfs3().noAuth().build();
96-
READDIR3args args = NfsV3Ops.readDir(dirInode, 10); // 10 bytes - not enough for anything
98+
READDIR3args args = NfsV3Ops.readDir(dirInodePseudoFS, 10); // 10 bytes - not enough for anything
9799
READDIR3res result = nfsServer.NFSPROC3_READDIR_3(call, args);
98100

99101
Assert.assertEquals(nfsstat.NFSERR_TOOSMALL, result.status); // error response
@@ -112,7 +114,7 @@ public void testContinueReadingAfterEOF() throws Exception {
112114

113115
// set up and execute the 1st call - no cookie, but very tight size limit
114116
RpcCall call = new RpcCallBuilder().from("1.2.3.4", "someHost.acme.com", 42).nfs3().noAuth().build();
115-
READDIR3args args = NfsV3Ops.readDir(dirInode);
117+
READDIR3args args = NfsV3Ops.readDir(dirInodePseudoFS);
116118
READDIR3res result = nfsServer.NFSPROC3_READDIR_3(call, args);
117119

118120
Assert.assertEquals(nfsstat.NFS_OK, result.status); // response ok
@@ -122,7 +124,7 @@ public void testContinueReadingAfterEOF() throws Exception {
122124
// reading after we got EOF
123125
long cookie = result.resok.reply.entries.nextentry.cookie.value.value;
124126
cookieVerifier = result.resok.cookieverf.value;
125-
args = NfsV3Ops.readDir(dirInode, cookie, cookieVerifier);
127+
args = NfsV3Ops.readDir(dirInodePseudoFS, cookie, cookieVerifier);
126128
result = nfsServer.NFSPROC3_READDIR_3(call, args);
127129

128130
Assert.assertEquals(nfsstat.NFS_OK, result.status); // response ok
@@ -145,7 +147,7 @@ public void testSemiValidVerifier() throws Exception {
145147
long cookie = 1;
146148

147149
RpcCall call = new RpcCallBuilder().from("1.2.3.4", "someHost.acme.com", 42).nfs3().noAuth().build();
148-
READDIR3args args = NfsV3Ops.readDir(dirInode, cookie, cookieVerifier);
150+
READDIR3args args = NfsV3Ops.readDir(dirInodePseudoFS, cookie, cookieVerifier);
149151
READDIR3res result = nfsServer.NFSPROC3_READDIR_3(call, args);
150152

151153
Assert.assertEquals(nfsstat.NFS_OK, result.status); // error response
@@ -169,7 +171,7 @@ public void testEofIfLastEntryDoesNotFit() throws Exception {
169171
when(vfs.list(eq(dirInode), any(), anyLong())).thenReturn(new DirectoryStream(cookieVerifier, dirContents));
170172

171173
RpcCall call = new RpcCallBuilder().from("1.2.3.4", "someHost.acme.com", 42).nfs3().noAuth().build();
172-
READDIR3args args = NfsV3Ops.readDir(dirInode, 0, cookieVerifier, 836); // only 22 entries will fit
174+
READDIR3args args = NfsV3Ops.readDir(dirInodePseudoFS, 0, cookieVerifier, 836); // only 22 entries will fit
173175
READDIR3res result = nfsServer.NFSPROC3_READDIR_3(call, args);
174176

175177
int n = 0;

0 commit comments

Comments
 (0)