1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//! Device authentication
use async_trait::async_trait;
use fantoccini::error::CmdError;
use http::Method;
use serde_json::json;
use crate::{AndroidClient, AppiumClientTrait, IOSClient};
use crate::commands::AppiumCommand;

/// Finger authentication (Android authentication)
#[async_trait]
pub trait AuthenticatesByFinger : AppiumClientTrait {
    async fn use_finger_print(&self, id: u8) -> Result<(), CmdError> {
        self.issue_cmd(AppiumCommand::Custom(
            Method::POST,
            "appium/device/finger_print".to_string(),
            Some(json!({
                "fingerprintId": id
            }))
        )).await?;
        
        Ok(())
    }
}

#[async_trait]
impl AuthenticatesByFinger for AndroidClient {}

/// TouchID (iPhone authentication)
#[async_trait]
pub trait PerformsTouchID : AppiumClientTrait {
    /// Simulate touchId event.
    async fn perform_touch_id(&self, successful_scan: bool) -> Result<(), CmdError> {
        self.issue_cmd(AppiumCommand::Custom(
            Method::POST,
            "appium/simulator/touch_id".to_string(),
            Some(json!({
                "match": successful_scan
            })),
        )).await?;
        Ok(())
    }

    /// Enrolls touchId in iOS Simulators. This call will only work if Appium process
    /// or its parent application (e.g. Terminal.app or Appium.app) has access to Mac OS accessibility
    /// in System Preferences > Security & Privacy > Privacy > Accessibility list.
    async fn toggle_touch_id_enrollment(&self, enabled: bool) -> Result<(), CmdError> {
        self.issue_cmd(AppiumCommand::Custom(
            Method::POST,
            "appium/simulator/toggle_touch_id_enrollment".to_string(),
            Some(json!({
                "enabled": enabled
            })),
        )).await?;
        Ok(())
    }
}

#[async_trait]
impl PerformsTouchID for IOSClient {}