mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-09 09:54:25 +09:00
torture_sftpserver.c: Add test for O_TRUNC while opening files
Signed-off-by: Eshan Kelkar <eshankelkar@galorithm.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
This commit is contained in:
committed by
Jakub Jelen
parent
aa681c268e
commit
6c4e4a9e1c
@@ -507,10 +507,10 @@ static void torture_server_test_sftp_function(void **state)
|
||||
static void torture_server_sftp_open_read_write(void **state)
|
||||
{
|
||||
struct test_server_st *tss = *state;
|
||||
struct torture_state *s;
|
||||
struct torture_sftp *tsftp;
|
||||
sftp_session sftp;
|
||||
ssh_session session;
|
||||
struct torture_state *s = NULL;
|
||||
struct torture_sftp *tsftp = NULL;
|
||||
sftp_session sftp = NULL;
|
||||
ssh_session session = NULL;
|
||||
sftp_attributes a = NULL;
|
||||
sftp_file new_file = NULL;
|
||||
char tmp_file[PATH_MAX] = {0};
|
||||
@@ -566,6 +566,30 @@ static void torture_server_sftp_open_read_write(void **state)
|
||||
assert_int_equal(a->type, SSH_FILEXFER_TYPE_REGULAR);
|
||||
sftp_attributes_free(a);
|
||||
|
||||
/*
|
||||
* Now that file exists and contains some data, lets try O_TRUNC,
|
||||
* mode is ignored
|
||||
*/
|
||||
new_file = sftp_open(sftp, tmp_file, O_WRONLY | O_TRUNC, 0);
|
||||
assert_non_null(new_file);
|
||||
|
||||
/* Verify that the existing data in the file has been truncated */
|
||||
a = sftp_stat(sftp, tmp_file);
|
||||
assert_non_null(a);
|
||||
assert_int_equal(a->size, 0); /* No content due to truncation */
|
||||
sftp_attributes_free(a);
|
||||
|
||||
/* Write should work ok */
|
||||
write_len = sftp_write(new_file, data, sizeof(data));
|
||||
assert_int_equal(write_len, sizeof(data));
|
||||
|
||||
/* Reading should fail */
|
||||
read_len = sftp_read(new_file, read_data, sizeof(read_data));
|
||||
assert_int_equal(read_len, SSH_ERROR);
|
||||
|
||||
rc = sftp_close(new_file);
|
||||
assert_ssh_return_code(session, rc);
|
||||
|
||||
/*
|
||||
* Now, lets try O_APPEND, mode is ignored
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user