rusftp/message/
realpath.rs

1// This file is part of the rusftp project
2//
3// Copyright (C) ANEO, 2024-2024. All rights reserved.
4//
5// Licensed under the Apache License, Version 2.0 (the "License")
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9//     http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16
17use serde::{Deserialize, Serialize};
18
19use crate::message::Path;
20
21/// Request to canonicalize a path.
22///
23/// The response will contain a single entry whose attributes have dummy values.
24///
25/// It is answered with [`Name`](crate::message::Name) in case of success
26/// and [`Status`](crate::message::Status) in case of failure.
27///
28/// internal: `SSH_FXP_REALPATH`
29#[derive(Debug, Default, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
30pub struct RealPath {
31    /// Path to canonicalize
32    pub path: Path,
33}
34
35#[cfg(test)]
36mod test {
37    use crate::message::{
38        test_utils::{encode_decode, fail_decode, BYTES_INVALID, BYTES_VALID},
39        Path,
40    };
41
42    use super::RealPath;
43
44    #[test]
45    fn encode_success() {
46        for (bytes, encoded) in BYTES_VALID {
47            encode_decode(
48                RealPath {
49                    path: Path(bytes.to_owned()),
50                },
51                encoded,
52            );
53        }
54    }
55
56    #[test]
57    fn decode_failure() {
58        for (bytes, expected) in BYTES_INVALID {
59            assert_eq!(fail_decode::<RealPath>(bytes), expected);
60        }
61    }
62}