api/src/test/java/edu/utexas/tacc/tapis/files/api/resources/ITestUtilsRoutes.java
@Test(dataProvider = "testSystemsProvider")
  public void testLinuxChown(TapisSystem testSystem) throws Exception
  {
    when(systemsClient.getSystemWithCredentials(any(), any())).thenReturn(testSystem);
    // Create file
    addTestFilesToSystem(testSystem, TEST_FILE3, TEST_FILE_SIZE);
    // Get stat info and check file properties
    FileStatInfoResponse response1 = target(String.format("%s/%s/%s", UTILS_ROUTE, SYSTEM_ID, TEST_FILE3))
            .request()
            .accept(MediaType.APPLICATION_JSON)
            .header("x-tapis-token", getServiceJwt())
            .header("x-tapis-user", TEST_USR1)
            .header("x-tapis-tenant", TENANT)
            .get(FileStatInfoResponse.class);
    Assert.assertNotNull(response1);
    FileStatInfo fileStatInfo = response1.getResult();
    validateFileProperties(fileStatInfo, TEST_FILE3, TEST_FILE_PERMS);

    // Run chown testuser
    var req = new NativeLinuxOpRequest();
    req.setOperation(NativeLinuxOperation.CHOWN);
    req.setArgument(TEST_USR);
    NativeLinuxOpResultResponse response2 = target(String.format("%s/%s/%s", UTILS_ROUTE, SYSTEM_ID, TEST_FILE3))
            .request()
            .accept(MediaType.APPLICATION_JSON)
            .header("x-tapis-token", getJwtForUser(TENANT, TEST_USR1))
            .post(Entity.json(req), NativeLinuxOpResultResponse.class);
    Assert.assertNotNull(response2);
    NativeLinuxOpResult result = response2.getResult();
    Assert.assertNotNull(result);
    System.out.printf("NativeLinuxOp result:%n%s%n", result);
    Assert.assertEquals(result.getExitCode(), 0);

    // Run chown testuser_new, should have exitCode=1
    req = new NativeLinuxOpRequest();
    req.setOperation(NativeLinuxOperation.CHOWN);
    req.setArgument(TEST_USR_NEW);
    response2 = target(String.format("%s/%s/%s", UTILS_ROUTE, SYSTEM_ID, TEST_FILE3))
            .request()
            .accept(MediaType.APPLICATION_JSON)
            .header("x-tapis-token", getJwtForUser(TENANT, TEST_USR1))
            .post(Entity.json(req), NativeLinuxOpResultResponse.class);
    Assert.assertNotNull(response2);
    result = response2.getResult();
    Assert.assertNotNull(result);
    System.out.printf("NativeLinuxOp result:%n%s%n", result);
    Assert.assertEquals(result.getExitCode(), 1);
    Assert.assertFalse(StringUtils.isBlank(result.getStdErr()));
    Assert.assertTrue(result.getStdErr().contains("invalid user"));
  }
/*
   * Test linux chown operation.
   * Currently there is only one user defined on the test system.
   * Check that:
   *   - chown to same user runs without error
   *   - chown to undefined username returns with exitCode=1 and stdErr contains "invalid user"
   */
Test linux chown operation.
Currently there is only one user defined on the test system.
Check that:
- chown to same user runs without error
- chown to undefined username returns with exitCode=1 and stdErr contains "invalid user"
Test linux chown operation . Currently there is only one user defined on the test system . Check that : - chown to same user runs without error - chown to undefined username returns with exitCode = 1 and stdErr contains " invalid user "
@Test(dataProvider = "testSystemsProvider")
  public void testLinuxChown(TapisSystem testSystem) throws Exception
  {
    when(systemsClient.getSystemWithCredentials(any(), any())).thenReturn(testSystem);
    addTestFilesToSystem(testSystem, TEST_FILE3, TEST_FILE_SIZE);
    FileStatInfoResponse response1 = target(String.format("%s/%s/%s", UTILS_ROUTE, SYSTEM_ID, TEST_FILE3))
            .request()
            .accept(MediaType.APPLICATION_JSON)
            .header("x-tapis-token", getServiceJwt())
            .header("x-tapis-user", TEST_USR1)
            .header("x-tapis-tenant", TENANT)
            .get(FileStatInfoResponse.class);
    Assert.assertNotNull(response1);
    FileStatInfo fileStatInfo = response1.getResult();
    validateFileProperties(fileStatInfo, TEST_FILE3, TEST_FILE_PERMS);
    var req = new NativeLinuxOpRequest();
    req.setOperation(NativeLinuxOperation.CHOWN);
    req.setArgument(TEST_USR);
    NativeLinuxOpResultResponse response2 = target(String.format("%s/%s/%s", UTILS_ROUTE, SYSTEM_ID, TEST_FILE3))
            .request()
            .accept(MediaType.APPLICATION_JSON)
            .header("x-tapis-token", getJwtForUser(TENANT, TEST_USR1))
            .post(Entity.json(req), NativeLinuxOpResultResponse.class);
    Assert.assertNotNull(response2);
    NativeLinuxOpResult result = response2.getResult();
    Assert.assertNotNull(result);
    System.out.printf("NativeLinuxOp result:%n%s%n", result);
    Assert.assertEquals(result.getExitCode(), 0);
    _new, should have exitCode=1
    req = new NativeLinuxOpRequest();
    req.setOperation(NativeLinuxOperation.CHOWN);
    req.setArgument(TEST_USR_NEW);
    response2 = target(String.format("%s/%s/%s", UTILS_ROUTE, SYSTEM_ID, TEST_FILE3))
            .request()
            .accept(MediaType.APPLICATION_JSON)
            .header("x-tapis-token", getJwtForUser(TENANT, TEST_USR1))
            .post(Entity.json(req), NativeLinuxOpResultResponse.class);
    Assert.assertNotNull(response2);
    result = response2.getResult();
    Assert.assertNotNull(result);
    System.out.printf("NativeLinuxOp result:%n%s%n", result);
    Assert.assertEquals(result.getExitCode(), 1);
    Assert.assertFalse(StringUtils.isBlank(result.getStdErr()));
    Assert.assertTrue(result.getStdErr().contains("invalid user"));
  }
@ Test ( dataProvider = "testSystemsProvider" ) public void testLinuxChown ( TapisSystem testSystem ) throws Exception { when ( systemsClient . getSystemWithCredentials ( any ( ) , any ( ) ) ) . thenReturn ( testSystem ) ; addTestFilesToSystem ( testSystem , TEST_FILE3 , TEST_FILE_SIZE ) ; FileStatInfoResponse response1 = target ( String . format ( "%s/%s/%s" , UTILS_ROUTE , SYSTEM_ID , TEST_FILE3 ) ) . request ( ) . accept ( MediaType . APPLICATION_JSON ) . header ( "x-tapis-token" , getServiceJwt ( ) ) . header ( "x-tapis-user" , TEST_USR1 ) . header ( "x-tapis-tenant" , TENANT ) . get ( FileStatInfoResponse . class ) ; Assert . assertNotNull ( response1 ) ; FileStatInfo fileStatInfo = response1 . getResult ( ) ; validateFileProperties ( fileStatInfo , TEST_FILE3 , TEST_FILE_PERMS ) ; var req = new NativeLinuxOpRequest ( ) ; req . setOperation ( NativeLinuxOperation . CHOWN ) ; req . setArgument ( TEST_USR ) ; NativeLinuxOpResultResponse response2 = target ( String . format ( "%s/%s/%s" , UTILS_ROUTE , SYSTEM_ID , TEST_FILE3 ) ) . request ( ) . accept ( MediaType . APPLICATION_JSON ) . header ( "x-tapis-token" , getJwtForUser ( TENANT , TEST_USR1 ) ) . post ( Entity . json ( req ) , NativeLinuxOpResultResponse . class ) ; Assert . assertNotNull ( response2 ) ; NativeLinuxOpResult result = response2 . getResult ( ) ; Assert . assertNotNull ( result ) ; System . out . printf ( "NativeLinuxOp result:%n%s%n" , result ) ; Assert . assertEquals ( result . getExitCode ( ) , 0 ) ; req = new NativeLinuxOpRequest ( ) ; req . setOperation ( NativeLinuxOperation . CHOWN ) ; req . setArgument ( TEST_USR_NEW ) ; response2 = target ( String . format ( "%s/%s/%s" , UTILS_ROUTE , SYSTEM_ID , TEST_FILE3 ) ) . request ( ) . accept ( MediaType . APPLICATION_JSON ) . header ( "x-tapis-token" , getJwtForUser ( TENANT , TEST_USR1 ) ) . post ( Entity . json ( req ) , NativeLinuxOpResultResponse . class ) ; Assert . assertNotNull ( response2 ) ; result = response2 . getResult ( ) ; Assert . assertNotNull ( result ) ; System . out . printf ( "NativeLinuxOp result:%n%s%n" , result ) ; Assert . assertEquals ( result . getExitCode ( ) , 1 ) ; Assert . assertFalse ( StringUtils . isBlank ( result . getStdErr ( ) ) ) ; Assert . assertTrue ( result . getStdErr ( ) . contains ( "invalid user" ) ) ; }
Test linux chown operation.
Test linux chown operation .
// Create file // Get stat info and check file properties // Run chown testuser // Run chown testuser_new, should have exitCode=1