anchor.diff:          get_shared_file_attrs_test,
           get_attrs_on_provider_not_supporting_space_test,
   
  -        set_mode_test
  +        set_file_mode_test,
  +        set_shared_file_mode_test,
  +        set_mode_on_provider_not_supporting_space_test
       ]).
   
   
  
positive.code:         end,
          ?assertEqual({ExpCode, ExpBody}, {RespCode, RespBody})
      end,
      ValidateRestOperationNotSupportedFun = fun(_, {ok, ?HTTP_400_BAD_REQUEST, Response}) ->
          ?assertEqual(?REST_ERROR(?ERROR_NOT_SUPPORTED), Response)
      end,
  
      ConstructVerifyEnvForSuccessfulCallsFun = fun(FileGuid) -> fun
          (expected_failure, #api_test_ctx{node = TestNode}) ->
              ?assertMatch(8#777, GetMode(TestNode, FileGuid), ?ATTEMPTS),
              true;
          (expected_success, #api_test_ctx{client = ?USER_IN_SPACE_2_AUTH, node = TestNode}) ->
              ?assertMatch(8#777, GetMode(TestNode, FileGuid), ?ATTEMPTS),
              true;
          (expected_success, #api_test_ctx{client = ?USER_IN_BOTH_SPACES_AUTH, data = #{<<"mode">> := ModeBin}}) ->
              Mode = binary_to_integer(ModeBin, 8),
              lists:foreach(fun(Node) -> ?assertMatch(Mode, GetMode(Node, FileGuid), ?ATTEMPTS) end, Providers),
              true
      end end,
  
      lists:foreach(fun({FileType, FilePath, FileGuid}) ->
          {ok, FileObjectId} = file_id:guid_to_objectid(FileGuid),
  
          ShareGuid = file_id:guid_to_share_guid(FileGuid, ShareId),
          {ok, ShareObjectId} = file_id:guid_to_objectid(ShareGuid),
  
          ?assert(api_test_runner:run_tests(Config, [
  
              %% TEST SET MODE FOR FILE IN NORMAL MODE
  
              #scenario_spec{
                  name = <<"Set mode for ", FileType/binary, " using /data/ rest endpoint">>,
                  type = rest,
                  target_nodes = Providers,
                  client_spec = ClientSpecForSpace2Scenarios,
                  prepare_args_fun = ConstructPrepareRestArgsFun(FileObjectId),
                  validate_result_fun = ValidateRestSuccessfulCallFun,
                  verify_fun = ConstructVerifyEnvForSuccessfulCallsFun(FileGuid),
                  data_spec = DataSpec
              },
              #scenario_spec{
                  name = <<"Set mode for ", FileType/binary, " using /files/ rest endpoint">>,
                  type = rest_with_file_path,
                  target_nodes = Providers,
                  client_spec = ClientSpecForSpace2Scenarios,
                  prepare_args_fun = ConstructPrepareDeprecatedFilePathRestArgsFun(FilePath),
                  validate_result_fun = ValidateRestSuccessfulCallFun,
                  verify_fun = ConstructVerifyEnvForSuccessfulCallsFun(FileGuid),
                  data_spec = DataSpec
              },
              #scenario_spec{
                  name = <<"Set mode for ", FileType/binary, " using /files-id/ rest endpoint">>,
                  type = rest,
                  target_nodes = Providers,
                  client_spec = ClientSpecForSpace2Scenarios,
                  prepare_args_fun = ConstructPrepareDeprecatedFileIdRestArgsFun(FileObjectId),
                  validate_result_fun = ValidateRestSuccessfulCallFun,
                  verify_fun = ConstructVerifyEnvForSuccessfulCallsFun(FileGuid),
                  data_spec = DataSpec
              },
              #scenario_spec{
                  name = <<"Set mode for ", FileType/binary, " using gs api">>,
                  type = gs,
                  target_nodes = Providers,
                  client_spec = ClientSpecForSpace2Scenarios,
                  prepare_args_fun = ConstructPrepareGsArgsFun(FileGuid, private),
                  validate_result_fun = fun(TestCtx, Result) ->
                      case GetExpectedResultFun(TestCtx) of
                          ok ->
                              ?assertEqual({ok, undefined}, Result);
                          {error, _} = ExpError ->
                              ?assertEqual(ExpError, Result)
                      end
                  end,
                  verify_fun = ConstructVerifyEnvForSuccessfulCallsFun(FileGuid),
                  data_spec = DataSpec
              }
          ])),
  
          %% TEST SET MODE FOR SHARED FILE SHOULD FAIL
  
          % Reset mode for file
          lists:foreach(fun(Node) -> SetMode(Node, FileGuid, 8#777) end, Providers),
  
          VerifyEnvForShareCallsFun = fun(_, #api_test_ctx{node = Node}) ->
              ?assertMatch(8#777, GetMode(Node, FileGuid)),
              true
          end,
  
          ?assert(api_test_runner:run_tests(Config, [
  
              #scenario_spec{
                  name = <<"Set mode for shared ", FileType/binary, " using /data/ rest endpoint">>,
                  type = rest_not_supported,
                  target_nodes = Providers,
                  client_spec = ClientSpecForShareScenarios,
                  prepare_args_fun = ConstructPrepareRestArgsFun(ShareObjectId),
                  validate_result_fun = ValidateRestOperationNotSupportedFun,
                  verify_fun = VerifyEnvForShareCallsFun,
                  data_spec = DataSpec
              },
              #scenario_spec{
                  name = <<"Set mode for shared ", FileType/binary, " using /files-id/ rest endpoint">>,
                  type = rest_not_supported,
                  target_nodes = Providers,
                  client_spec = ClientSpecForShareScenarios,
                  prepare_args_fun = ConstructPrepareDeprecatedFileIdRestArgsFun(ShareObjectId),
                  validate_result_fun = ValidateRestOperationNotSupportedFun,
                  verify_fun = VerifyEnvForShareCallsFun,
                  data_spec = DataSpec
              },
              #scenario_spec{
                  name = <<"Set mode for shared ", FileType/binary, " using gs public api">>,
                  type = gs_not_supported,
                  target_nodes = Providers,
                  client_spec = ClientSpecForShareScenarios,
                  prepare_args_fun = ConstructPrepareGsArgsFun(ShareGuid, public),
                  validate_result_fun = fun(_TestCaseCtx, Result) ->
                      ?assertEqual(?ERROR_NOT_SUPPORTED, Result)
                  end,
                  verify_fun = VerifyEnvForShareCallsFun,
                  data_spec = DataSpec
              },
              #scenario_spec{
                  name = <<"Set mode for shared ", FileType/binary, " using private gs api">>,
                  type = gs,
                  target_nodes = Providers,
                  client_spec = ClientSpecForShareScenarios,
                  prepare_args_fun = ConstructPrepareGsArgsFun(ShareGuid, private),
                  validate_result_fun = fun(_, Result) ->
                      ?assertEqual(?ERROR_UNAUTHORIZED, Result)
                  end,
                  verify_fun = VerifyEnvForShareCallsFun,
                  data_spec = DataSpec
              }
          ]))
      end, [
          {<<"dir">>, DirPath, DirGuid},
          {<<"file">>, RegularFilePath, RegularFileGuid}
      ]),
  
      %% TEST SET MODE FOR FILE ON PROVIDER NOT SUPPORTING USER
  
      Space1RootDirPath = filename:join(["/", ?SPACE_1, ?SCENARIO_NAME]),
      {ok, Space1RootDirGuid} = lfm_proxy:mkdir(Provider1, GetSessionFun(Provider1), Space1RootDirPath, 8#777),
      {ok, Space1RootObjectId} = file_id:guid_to_objectid(Space1RootDirGuid),
  
      ClientSpecForSpace1Scenarios = #client_spec{
          correct = [?USER_IN_SPACE_1_AUTH, ?USER_IN_BOTH_SPACES_AUTH],
          unauthorized = [?NOBODY],
          forbidden = [?USER_IN_SPACE_2_AUTH],
          supported_clients_per_node = SupportedClientsPerNode
      },
      Provider2DomainBin = ?GET_DOMAIN_BIN(Provider2),
  
      ValidateRestSetMetadataOnProvidersNotSupportingUserFun = fun(_TestCtx, {ok, RespCode, RespBody}) ->
          ExpCode = ?HTTP_400_BAD_REQUEST,
          ExpBody = ?REST_ERROR(?ERROR_SPACE_NOT_SUPPORTED_BY(Provider2DomainBin)),
          ?assertEqual({ExpCode, ExpBody}, {RespCode, RespBody})
      end,
      VerifyEnvFunForSetModeInSpace1Scenarios = fun
          (_, #api_test_ctx{node = Node}) ->
              ?assertMatch(8#777, GetMode(Node, Space1RootDirGuid), ?ATTEMPTS),
              true
      end,
  
      ?assert(api_test_runner:run_tests(Config, [
          #scenario_spec{
              name = <<"Set mode for root dir in ", ?SPACE_1/binary, " on provider not supporting user using /data/ rest endpoint">>,
              type = rest,
              target_nodes = [Provider2],
              client_spec = ClientSpecForSpace1Scenarios,
              prepare_args_fun = ConstructPrepareRestArgsFun(Space1RootObjectId),
              validate_result_fun = ValidateRestSetMetadataOnProvidersNotSupportingUserFun,
              verify_fun = VerifyEnvFunForSetModeInSpace1Scenarios,
              data_spec = DataSpec
          },
          #scenario_spec{
              name = <<"Set mode for root dir in ", ?SPACE_1/binary, " on provider not supporting user using /files/ rest endpoint">>,
              type = rest_with_file_path,
              target_nodes = [Provider2],
              client_spec = ClientSpecForSpace1Scenarios,
              prepare_args_fun = ConstructPrepareDeprecatedFilePathRestArgsFun(Space1RootDirPath),
              validate_result_fun = ValidateRestSetMetadataOnProvidersNotSupportingUserFun,
              verify_fun = VerifyEnvFunForSetModeInSpace1Scenarios,
              data_spec = DataSpec
          },
          #scenario_spec{
              name = <<"Set mode for root dir in ", ?SPACE_1/binary, " on provider not supporting user using /files-id/ rest endpoint">>,
              type = rest,
              target_nodes = [Provider2],
              client_spec = ClientSpecForSpace1Scenarios,
              prepare_args_fun = ConstructPrepareDeprecatedFileIdRestArgsFun(Space1RootObjectId),
              validate_result_fun = ValidateRestSetMetadataOnProvidersNotSupportingUserFun,
              verify_fun = VerifyEnvFunForSetModeInSpace1Scenarios,
              data_spec = DataSpec
          },
          #scenario_spec{
              name = <<"Set mode for root dir in ", ?SPACE_1/binary, " on provider not supporting user using gs api">>,
              type = gs,
              target_nodes = [Provider2],
              client_spec = ClientSpecForSpace1Scenarios,
              prepare_args_fun = ConstructPrepareGsArgsFun(Space1RootDirGuid, private),
              validate_result_fun = fun(_TestCtx, Result) ->
                  ?assertEqual(?ERROR_SPACE_NOT_SUPPORTED_BY(Provider2DomainBin), Result)
              end,
              verify_fun = VerifyEnvFunForSetModeInSpace1Scenarios,
              data_spec = DataSpec
          }
      ])).
  
  
  %%%===================================================================
  
negative.code: %%%===================================================================
  
  
  set_file_mode_test(Config) ->
      [P2, P1] = Providers = ?config(op_worker_nodes, Config),
      SessIdP1 = ?USER_IN_BOTH_SPACES_SESS_ID(P1, Config),
      SessIdP2 = ?USER_IN_BOTH_SPACES_SESS_ID(P2, Config),
  
      GetSessionFun = fun(Node) ->
          ?config({session_id, {?USER_IN_BOTH_SPACES, ?GET_DOMAIN(Node)}}, Config)
      end,
  
      FileType = api_test_utils:randomly_choose_file_type_for_test(),
      FilePath = filename:join(["/", ?SPACE_2, ?RANDOM_FILE_NAME()]),
      {ok, FileGuid} = api_test_utils:create_file(FileType, P1, SessIdP1, FilePath, 8#777),
      {ok, FileObjectId} = file_id:guid_to_objectid(FileGuid),
  
      api_test_utils:wait_for_file_sync(P2, SessIdP2, FileGuid),
  
      GetExpectedResultFun = fun
          (#api_test_ctx{client = ?USER_IN_BOTH_SPACES_AUTH}) -> ok;
  