# 安全
Appium團隊在盡一切努力提高Appium 服務端的安全性。尤其在多租戶環境或多個用戶在同一個服務端上運行會話時,安全性尤為必要。一般來說,如果您在本地運行自己的Appium服務,而且不會和其他人共享它,或者將服務暴露在互聯網上,那么可以不用擔心安全問題,您可以放心大膽的啟用Appium所有的功能。
但是,鑒于很多Appium的用戶可能無法保證有一個安全的運行環境,Appium團隊將許多功能后置于安全保護機制之后,強制系統管理員(負責啟動Appium服務的家伙)顯示的選擇啟用這些置于安全機制之后的功能。
出于安全考慮,Appium的客戶端會話不能通過設置capabilities,以發送請求的方式來開啟那些(啟用了安全機制的)功能。這屬于啟動Appium服務器那個家伙的責任。
## 安全相關的服務啟動參數
[server-args](../writing-running-appium/server-args.md)文檔概述了從命令行啟動Appium可以傳遞的三個相關參數:
* `--relaxed-security`:設置該項會開啟所有非安全功能(`--deny-insecure`沒有設置為的情況下;參考下方描述)
* `--allow-insecure`:該項設置啟用給定的功能列,它跟的參數是逗號分隔符的功能列表,或者是一個包含功能列表(一個功能占一行)的文件路徑。比如:`--allow-insecure=adb_shell`的設置僅會開啟adb shell的功能。該設置是可以生效的,但結合設置`--relaxed-security`參數(啟用所有功能的設置)就沒有意義了。
* `--deny-insecure`:該項設置同樣可以傳入給定的功能列或者是一個包含功能列表(一個功能占一行)的文件路徑。不管是設置了`--relaxed-security` ,還是設置了`--allow-insecure`,`--deny-insecure`列出的任何功能都將被禁用。
## 不安全的功能
每個Appium驅動程序負責其自身的安全性,并可以創建自己的功能名稱。下表是我們所知道的Appium驅動程序官方支持的的功能和名稱。
|特性名稱|描述|AutomationName|
|------------|-----------|-------|
|`get_server_logs`|允許通過Webdriver日志接口檢索Appium服務器日志|IOS, XCUITest, Android, UiAutomator2, Espresso|
|`adb_shell`|允許通過ADB命令執行任意的`mobile: shell`命令。|Android, UiAutomator2, Espresso|
|`shutdown_other_sims`|允許任何會話使用capability來關閉任何服務器上正在運行的模擬器|XCUITest|
|`perf_record`|允許記錄系統性能和其他的模擬器指標|XCUITest|
|`record_audio`|允許記錄主機的音頻輸入|XCUITest|
|`chromedriver_autodownload`|允許自動下載適當的ChromeDriver版本 |Android, UiAutomator2, Espresso|
|`execute_driver_script`| 允許發送包含多個Appium命令參數的請求。參考閱讀 [文檔](https://github.com/appium/appium/blob/master../commands/session/execute-driver.md) 獲得更多細節|All|
也可以參考下面的鏈接,它們可能包含額外的設置項。
- [appium-android-driver](https://github.com/appium/appium-android-driver#opt-in-features-with-security-risk)
- [appium-xcuitest-driver](https://github.com/appium/appium-xcuitest-driver#opt-in-features-with-security-risk)
- [appium-mac-driver](https://github.com/appium/appium-mac-driver#opt-in-features-with-security-risk)
## 寫給Driver的開發者
兩個方法存在于擴展了`BaseDriver`的類當中,使得在檢查不安全功能的可用性時,Driver程序的開發人員的工作更加輕松:
* `this.isFeatureEnabled(name)`: 返回 true或false,取決于服務端安全設置的組合是否允許啟用有問題的功能。
* `this.ensureFeatureEnabled(name)`: 如果有問題的功能不被允許使用,會拋出一個包含有功能名稱和執行本文地址的錯誤。
- 關于TesterHome和MTSC
- 關于Appium
- 簡介
- Appium 客戶端
- 入門指南
- 已支持的平臺
- API 文檔
- Appium驅動
- XCUITest (iOS)
- XCUITest Real Devices (iOS)
- UIAutomation (iOS)
- UIAutomation Safari Launcher (iOS)
- UIAutomator (Android)
- UIAutomator2 (Android)
- Espresso (Android)
- Windows
- Mac
- Appium命令
- Status
- Execute Mobile Command
- Session
- Create
- End
- Get Session Capabilities
- Go Back
- Screenshot
- Source
- Timeouts
- Timeouts
- Implicit Wait
- Async Script
- Orientation
- Get Orientation
- Set Orientation
- Geolocation
- Get Geolocation
- Set Geolocation
- Logs
- Get Log Types
- Get Logs
- Events
- Log event
- Get events
- Settings
- Update Settings
- Get Device Settings
- Settings
- Update Settings
- Get Device Settings
- Execute Driver Script
- Device
- Activity
- Start Activity
- Current Activity
- Current Package
- App
- Install App
- Is App Installed
- Launch App
- Background App
- Close App
- Reset App
- Remove App
- Activate App
- Terminate App
- Get App State
- Get App Strings
- End Test Coverage
- Clipboard
- Get Clipboard
- Set Clipboard
- Emulator
- Power AC
- Power Capacity
- Files
- Push File
- Pull File
- Pull Folder
- Interactions
- Shake
- Lock
- Unlock
- Is Locked
- Rotate
- Keys
- Press keycode
- Long press keycode
- Hide Keyboard
- Is Keyboard Shown
- Network
- Toggle Airplane Mode
- Toggle Data
- Toggle WiFi
- Toggle Location Services
- Send SMS
- GSM Call
- GSM Signal
- GSM Voice
- Network Speed
- Performance Data
- Get Performance Data
- Performance Data Types
- Screen Recording
- Start Screen Recording
- Stop Screen Recording
- Simulator
- Perform Touch ID
- Toggle Touch ID Enrollment
- System
- Open Notifications
- System Bars
- System Time
- Display density
- Authentication
- Finger Print
- Element
- Find Element
- Find Elements
- Actions
- Click
- Send Keys
- Clear
- Attributes
- Text
- Name
- Attribute
- Selected
- Enabled
- Displayed
- Location
- Size
- Rect
- CSS Property
- Location in View
- Other
- Submit
- Active Element
- Equals Element
- Context
- Get Context
- Get All Contexts
- Set Context
- Interactions
- Mouse
- Move To
- Click
- Double Click
- Button Down
- Button Up
- Touch
- Single Tap
- Double Tap
- Move
- Touch Down
- Touch Up
- Long Press
- Scroll
- Flick
- Multi Touch Perform
- Touch Perform
- W3C Actions
- Web
- Window
- Set Window
- Close Window
- Get Handle
- Get Handles
- Get Title
- Get Window Size
- Set Window Size
- Get Window Position
- Set Window Position
- Maximize Window
- Navigation
- Go to URL
- Get URL
- Back
- Forward
- Refresh
- Storage
- Get All Cookies
- Set Cookie
- Delete Cookie
- Delete All Cookies
- Frame
- Switch to Frame
- Switch to Parent Frame
- Execute Async
- Execute
- 編寫 & 運行Appium腳本
- Running Tests
- Desired Capabilities
- The --default-capabilities flag
- Finding Elements
- Touch Actions
- CLI Arguments
- Server Security
- Web/Web Views
- Mobile Web Testing
- Automating Hybrid Apps
- Using ios-webkit-debug-proxy
- Using Chromedriver
- Image Comparison
- iOS
- Low-Level Insights on iOS Input Events
- XCUITest Mobile Gestures
- XCUITest Mobile App Management
- iOS Pasteboard Guide
- iOS Predicate Guide
- iOS Touch ID Guide
- iOS Install Certificate
- tvOS support
- Pushing/Pulling files
- Audio Capture
- Android
- Low-Level Insights on Android Input Events
- UiSelector Guide
- Espresso Datamatcher Guide
- Android Code Coverage Guide
- Activities Startup Troubleshooting Guide
- How To Execute Shell Commands On The Remote Device
- Android Device Screen Streaming
- How To Emulate IME Actions Generation
- How To Test Android App Bundle
- Other
- Reset Strategies
- Network Connection Guide
- Using Unicode with Appium
- Troubleshooting
- Tutorial
- Swipe Tutorial
- Screen
- Element
- Partial screen
- Simple
- Multiple scroll views
- Add scroll layout
- Tricks and Tips
- Screen
- Element
- Element search
- Fast
- Slow
- Guide
- 進階概念
- 定位圖像中的元素
- 使用定位元素的插件
- 遷移到 XCUITest
- 在 Appium 中使用 Selenium Grid
- Appium Logs Filtering
- 跨域 iframes
- 使用自定義 WDA 服務器
- 使用不同版本的 Xcode 運行
- The Event Timings API
- 并行測試的設置
- The Settings API
- Memory Collection
- 向Appium項目做貢獻
- 從源代碼運行 Appium
- 開發者概述
- 標準開發命令
- Appium 風格指南
- 如何編寫文檔
- Appium 包結構
- 鳴謝