# 安全
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 包结构
- 鸣谢