@Test public void testGetAccessRightsForUserGroup() throws IOException { Nfs3FileAttributes attr = Mockito.mock(Nfs3FileAttributes.class); Mockito.when(attr.getUid()).thenReturn(2); Mockito.when(attr.getGid()).thenReturn(3); Mockito.when(attr.getMode()).thenReturn(448); Mockito.when(attr.getType()).thenReturn(NfsFileType.NFSREG.toValue()); assertEquals("No access should be allowed as UID does not match attribute over mode 700", 0, Nfs3Utils.getAccessRightsForUserGroup(3, 3, null, attr)); Mockito.when(attr.getUid()).thenReturn(2); Mockito.when(attr.getGid()).thenReturn(3); Mockito.when(attr.getMode()).thenReturn(56); Mockito.when(attr.getType()).thenReturn(NfsFileType.NFSREG.toValue()); assertEquals("No access should be allowed as GID does not match attribute over mode 070", 0, Nfs3Utils.getAccessRightsForUserGroup(2, 4, null, attr)); Mockito.when(attr.getUid()).thenReturn(2); Mockito.when(attr.getGid()).thenReturn(3); Mockito.when(attr.getMode()).thenReturn(7); Mockito.when(attr.getType()).thenReturn(NfsFileType.NFSREG.toValue()); assertEquals("Access should be allowed as mode is 007 and UID/GID do not match", 61 , Nfs3Utils.getAccessRightsForUserGroup(1, 4, new int[] {5, 6}, attr)); Mockito.when(attr.getUid()).thenReturn(2); Mockito.when(attr.getGid()).thenReturn(10); Mockito.when(attr.getMode()).thenReturn(288); Mockito.when(attr.getType()).thenReturn(NfsFileType.NFSREG.toValue()); assertEquals("Access should be allowed as mode is 440 and Aux GID does match", 1 , Nfs3Utils.getAccessRightsForUserGroup(3, 4, new int[] {5, 16, 10}, attr)); Mockito.when(attr.getUid()).thenReturn(2); Mockito.when(attr.getGid()).thenReturn(10); Mockito.when(attr.getMode()).thenReturn(448); Mockito.when(attr.getType()).thenReturn(NfsFileType.NFSDIR.toValue()); assertEquals("Access should be allowed for dir as mode is 700 and UID does match", 31 , Nfs3Utils.getAccessRightsForUserGroup(2, 4, new int[] {5, 16, 10}, attr)); assertEquals("No access should be allowed for dir as mode is 700 even though GID does match", 0, Nfs3Utils.getAccessRightsForUserGroup(3, 10, new int[] {5, 16, 4}, attr)); assertEquals("No access should be allowed for dir as mode is 700 even though AuxGID does match", 0, Nfs3Utils.getAccessRightsForUserGroup(3, 20, new int[] {5, 10}, attr)); Mockito.when(attr.getUid()).thenReturn(2); Mockito.when(attr.getGid()).thenReturn(10); Mockito.when(attr.getMode()).thenReturn(457); Mockito.when(attr.getType()).thenReturn(NfsFileType.NFSDIR.toValue()); assertEquals("Access should be allowed for dir as mode is 711 and GID matches", 2 , Nfs3Utils.getAccessRightsForUserGroup(3, 10, new int[] {5, 16, 11}, attr)); }
public static int getAccessRightsForUserGroup(int uid, int gid, int[] auxGids, Nfs3FileAttributes attr) { int mode = attr.getMode(); if (uid == attr.getUid()) { return getAccessRights(mode >> 6, attr.getType()); } if (gid == attr.getGid()) { return getAccessRights(mode >> 3, attr.getType()); } if (auxGids != null) { for (int auxGid : auxGids) { if (attr.getGid() == auxGid) { return getAccessRights(mode >> 3, attr.getType()); } } } return getAccessRights(mode, attr.getType()); }
Nfs3Utils { public static int getAccessRightsForUserGroup(int uid, int gid, int[] auxGids, Nfs3FileAttributes attr) { int mode = attr.getMode(); if (uid == attr.getUid()) { return getAccessRights(mode >> 6, attr.getType()); } if (gid == attr.getGid()) { return getAccessRights(mode >> 3, attr.getType()); } if (auxGids != null) { for (int auxGid : auxGids) { if (attr.getGid() == auxGid) { return getAccessRights(mode >> 3, attr.getType()); } } } return getAccessRights(mode, attr.getType()); } }
Nfs3Utils { public static int getAccessRightsForUserGroup(int uid, int gid, int[] auxGids, Nfs3FileAttributes attr) { int mode = attr.getMode(); if (uid == attr.getUid()) { return getAccessRights(mode >> 6, attr.getType()); } if (gid == attr.getGid()) { return getAccessRights(mode >> 3, attr.getType()); } if (auxGids != null) { for (int auxGid : auxGids) { if (attr.getGid() == auxGid) { return getAccessRights(mode >> 3, attr.getType()); } } } return getAccessRights(mode, attr.getType()); }  }
Nfs3Utils { public static int getAccessRightsForUserGroup(int uid, int gid, int[] auxGids, Nfs3FileAttributes attr) { int mode = attr.getMode(); if (uid == attr.getUid()) { return getAccessRights(mode >> 6, attr.getType()); } if (gid == attr.getGid()) { return getAccessRights(mode >> 3, attr.getType()); } if (auxGids != null) { for (int auxGid : auxGids) { if (attr.getGid() == auxGid) { return getAccessRights(mode >> 3, attr.getType()); } } } return getAccessRights(mode, attr.getType()); }  static String getFileIdPath(FileHandle handle); static String getFileIdPath(long fileId); static HdfsFileStatus getFileStatus(DFSClient client, String fileIdPath); static Nfs3FileAttributes getNfs3FileAttrFromFileStatus(
      HdfsFileStatus fs, IdMappingServiceProvider iug); static Nfs3FileAttributes getFileAttr(DFSClient client,
      String fileIdPath, IdMappingServiceProvider iug); static WccAttr getWccAttr(DFSClient client, String fileIdPath); static WccAttr getWccAttr(Nfs3FileAttributes attr); static WccData createWccData(final WccAttr preOpAttr,
      DFSClient dfsClient, final String fileIdPath,
      final IdMappingServiceProvider iug); static void writeChannel(Channel channel, XDR out, int xid); static void writeChannelCommit(Channel channel, XDR out, int xid); static int getAccessRights(int mode, int type); static int getAccessRightsForUserGroup(int uid, int gid,
      int[] auxGids, Nfs3FileAttributes attr); static long bytesToLong(byte[] data); static byte[] longToByte(long v); }
Nfs3Utils { public static int getAccessRightsForUserGroup(int uid, int gid, int[] auxGids, Nfs3FileAttributes attr) { int mode = attr.getMode(); if (uid == attr.getUid()) { return getAccessRights(mode >> 6, attr.getType()); } if (gid == attr.getGid()) { return getAccessRights(mode >> 3, attr.getType()); } if (auxGids != null) { for (int auxGid : auxGids) { if (attr.getGid() == auxGid) { return getAccessRights(mode >> 3, attr.getType()); } } } return getAccessRights(mode, attr.getType()); }  static String getFileIdPath(FileHandle handle); static String getFileIdPath(long fileId); static HdfsFileStatus getFileStatus(DFSClient client, String fileIdPath); static Nfs3FileAttributes getNfs3FileAttrFromFileStatus(
      HdfsFileStatus fs, IdMappingServiceProvider iug); static Nfs3FileAttributes getFileAttr(DFSClient client,
      String fileIdPath, IdMappingServiceProvider iug); static WccAttr getWccAttr(DFSClient client, String fileIdPath); static WccAttr getWccAttr(Nfs3FileAttributes attr); static WccData createWccData(final WccAttr preOpAttr,
      DFSClient dfsClient, final String fileIdPath,
      final IdMappingServiceProvider iug); static void writeChannel(Channel channel, XDR out, int xid); static void writeChannelCommit(Channel channel, XDR out, int xid); static int getAccessRights(int mode, int type); static int getAccessRightsForUserGroup(int uid, int gid,
      int[] auxGids, Nfs3FileAttributes attr); static long bytesToLong(byte[] data); static byte[] longToByte(long v); final static String INODEID_PATH_PREFIX; final static String READ_RPC_START; final static String READ_RPC_END; final static String WRITE_RPC_START; final static String WRITE_RPC_END; }