Test4Enforcers: Test Case
Generation for Software
Enforcers
Oliviero Riganelli
University of Milano Bicocca
joint work with
Michell Guzman, Daniela Micucci and Leonardo Mariani
Runtime Enforcement
Enforcer
Actions Valid
Actions
Android(API Guides) Sept 20, 2020
Call release() to release the camera for use
by other applications. Applications should
release the camera immediately in onPause()
Untrusted App System
Violation
Policy
Enforcement Model
Untrusted App
Enforcer
Untrusted App
Actions Valid
Actions
Untrusted App System
onPause()req?/
onPause()api!
onPause()req?/release()api!; onPause()api!
open()req?/open()api!
release()req?/release()api!
Android(API Guides) Sept 20, 2020
Call release() to release the camera for use
by other applications. Applications should
release the camera immediately in onPause()
Policy
From Model to Code
Untrusted App
Enforcement Model
Self-enforcing App
Code Instrumentation
Issues with Enforcers
Expected Behavior
Modeled Behavior
Inaccurate Enforcement Models
Inconsistent Enforcer Implementations
Implemented Behavior
Modeled Behavior
Issues with Enforcers
Expected Behavior
Modeled Behavior
Inaccurate Enforcement Models
Inconsistent Enforcer Implementations
Implemented Behavior
Modeled Behavior
Faulty Enforcer Code
Implemented Behavior
Issues with Enforcers
Expected Behavior
Modeled Behavior
Inaccurate Enforcement Models
Goal
Enforcer Model
Test CasesTest4Enforcers
Test4Enforcers
Enforcement
Model
Generation of
Test Sequences
Concrete
Test Case
Generation
Gui Ripping
with Monitoring
App
Test
Cases
Test4Enforcers Model
onPause(),
onPause(), onPause(),
open(), onPause()
open(), onPause(), onPause()
open(), release(), onPause()
Test Sequences
onPause()req?/
onPause()api!
onPause()req?/release()api!; onPause()api!
open()req?/open()api!
release()req?/release()api!
Generation of Test Sequences
1. onPause()req
2. onPause()req, onPause()req
3. open()req, onPause()req
4. open()req, onPause()req, onPause()req
5. open()req, release()req, onPause()req
HSI-Method*
*Petrenko et al.: Testing deterministic implementations from nondeterministic fsm specifications. In: Proceedings of the IFIP TC6 International Workshop on
Testing of Communicating Systems (1996)
GUI Ripping with Monitoring
Touch buttons
Type text
Press HOME key
…
GUI Ripping with Monitoring
Touch buttons
Type text
Press HOME key
…
Actions in the
enforcement model
Test4Enforcers Model
GrantPermissionsActivity
<FIRST>
GrantPermissionsActivity
TouchEvent(“3”)
MainActivity
MainActivity
Launcher
KeyEvent(HOME)
release();onPause()
open()
TouchEvent(“ALLOW”) TouchEvent(“ALLOW”)
GrantPermissionsActivity
TouchEvent(“3”)
MainActivity
MainActivity
Launcher
KeyEvent(HOME)
release();onPause()
open()
TouchEvent(“ALLOW”) TouchEvent(“ALLOW”)
GrantPermissionsActivity
TouchEvent(“ALLOW”)
TouchEvent(“3”)
MainActivity
KeyEvent(HOME)
release();onPause()
open()
Test4Enforcers Model
KeyEvent(HOME)
STATE
GUI:
GrantPermissionsActivity
<FIRST>
GrantPermissionsActivity
<FIRST>
GrantPermissionsActivity
TouchEvent(“3”)
MainActivity
MainActivity
Launcher
KeyEvent(HOME)
release();onPause()
open()
TouchEvent(“ALLOW”) TouchEvent(“ALLOW”)
GrantPermissionsActivity
<FIRST>
GrantPermissionsActivity
TouchEvent(“ALLOW”)
GrantPermissionsActivity
<FIRST>
GrantPermissionsActivity
TouchEvent(“ALLOW”)
Test4Enforcers Model
Launcher
KeyEvent(HOME)
GrantPermissionsActivity
<FIRST>
EVENT
Type: Touch
View:
Command: adb shell input …
Trace: release();onPause()
Concrete Test Case Generation
1. TouchEvent(“ALLOW”), TouchEvent(“ALLOW”), KeyEvent(HOME)
Test Case
1. open()req, release()req, onPause()req
Test Sequence
Concrete Test Case Generation
1. open()req, release()req, onPause()req
Test Sequence
GrantPermissionsActivity
<FIRST>
GrantPermissionsActivity
TouchEvent(“3”)
MainActivity
MainActivity
Launcher
KeyEvent(HOME)
release();onPause()
open()
TouchEvent(“ALLOW”) TouchEvent(“ALLOW”)
Concrete Test Case Generation
1. open()req, release()req, onPause()req
1. TouchEvent(“ALLOW”), TouchEvent(“ALLOW”), KeyEvent(HOME)
Test Sequence
Test Case
GrantPermissionsActivity
<FIRST>
GrantPermissionsActivity
TouchEvent(“3”)
MainActivity
MainActivity
Launcher
KeyEvent(HOME)
release();onPause()
open()
TouchEvent(“ALLOW”) TouchEvent(“ALLOW”)
Test Case Oracles
Transparent
Enforcement
Actual
Enforcement
App with enforcer App without enforcer
fooCam has stopped
Open app again
Proof of Concept
Configuration
Google Pixel 2
Android 8.0
Metrics
# of covered test sequencesSize of models
APPs
Correct fooCam app
https://play.google.com/store/apps/details?id=net.phunehehe.foocam2&hl=EN
Enforcer
Faulty fooCam app
Size of Test4Enforcers models
0
75
150
225
300
States Transitions
Faulty fooCam Correct fooCam
# of covered test sequences
APP
Test Sequence Coverage
Faulty fooCam
onPause()req INFEASIBLE
onPause()req, onPause()req INFEASIBLE
open()req, onPause()req INFEASIBLE
open()req, onPause()req, onPause()req INFEASIBLE
open()req, release()req, onPause()req COVERED
Correct fooCam
onPause()req INFEASIBLE
onPause()req, onPause()req INFEASIBLE
open()req, onPause()req COVERED
open()req, onPause()req, onPause()req INFEASIBLE
open()req, release()req, onPause()req INFEASIBLE
Conclusions

Test4Enforcers: Test Case Generation for Software Enforcers