/* Ċ Ġ* ĠCopyright Ġ( c ) Ġ 2 0 2 0 ĠNew ĠVector ĠLtd Ċ Ġ* Ċ Ġ* ĠLicensed Ġunder Ġthe ĠApache ĠLicense , ĠVersion Ġ 2 . 0 Ġ( the Ġ" License "); Ċ Ġ* Ġyou Ġmay Ġnot Ġuse Ġthis Ġfile Ġexcept Ġin Ġcompliance Ġwith Ġthe ĠLicense . Ċ Ġ* ĠYou Ġmay Ġobtain Ġa Ġcopy Ġof Ġthe ĠLicense Ġat Ċ Ġ* Ċ Ġ* ĠĠĠĠ Ġhttp :// www . apache . org / licenses / LICENSE - 2 . 0 Ċ Ġ* Ċ Ġ* ĠUnless Ġrequired Ġby Ġapplicable Ġlaw Ġor Ġagreed Ġto Ġin Ġwriting , Ġsoftware Ċ Ġ* Ġdistributed Ġunder Ġthe ĠLicense Ġis Ġdistributed Ġon Ġan Ġ" AS ĠIS " ĠBASIS , Ċ Ġ* ĠWITHOUT ĠWARRANTIES ĠOR ĠCONDITIONS ĠOF ĠANY ĠKIND , Ġeither Ġexpress Ġor Ġimplied . Ċ Ġ* ĠSee Ġthe ĠLicense Ġfor Ġthe Ġspecific Ġlanguage Ġgoverning Ġpermissions Ġand Ċ Ġ* Ġlimitations Ġunder Ġthe ĠLicense . Ċ Ġ*/ Ċ Ċ package Ġim . vector . app Ċ Ċ import Ġandroid . app . Activity Ċ import Ġandroid . app . Instrumentation . Activity Result Ċ import Ġandroid . content . Intent Ċ import Ġandroidx . test . espress o . Esp ress o . on View Ċ import Ġandroidx . test . espress o . action . View Actions . click Ċ import Ġandroidx . test . espress o . action . View Actions . close Soft Keyboard Ċ import Ġandroidx . test . espress o . action . View Actions . press Back Ċ import Ġandroidx . test . espress o . action . View Actions . replace Text Ċ import Ġandroidx . test . espress o . action . View Actions . type Text Ċ import Ġandroidx . test . espress o . assertion . View Assertions . matches Ċ import Ġandroidx . test . espress o . intent . Intent s Ċ import Ġandroidx . test . espress o . intent . Intent s . int ending Ċ import Ġandroidx . test . espress o . intent . matcher . Intent Matchers . has Action Ċ import Ġandroidx . test . espress o . intent . matcher . Intent Matchers . is Internal Ċ import Ġandroidx . test . espress o . matcher . Root Matchers Ċ import Ġandroidx . test . espress o . matcher . View Matchers . is Displayed Ċ import Ġandroidx . test . espress o . matcher . View Matchers . is Root Ċ import Ġandroidx . test . espress o . matcher . View Matchers . with Id Ċ import Ġandroidx . test . espress o . matcher . View Matchers . with Text Ċ import Ġandroidx . test . ext . junit . rules . Activity Scenario Rule Ċ import Ġandroidx . test . ext . junit . runners . Android JUnit 4 Ċ import Ġandroidx . test . filters . Large Test Ċ import Ġim . vector . app . core . utils . get Matrix Instance Ċ import Ġim . vector . app . features . MainActivity Ċ import Ġim . vector . app . features . crypto . recover . Setup Mode Ċ import Ġim . vector . app . features . home . Home Activity Ċ import Ġorg . hamcrest . Core Matchers . not Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Ignore Ċ import Ġorg . junit . Rule Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ import Ġorg . matrix . android . sdk . api . session . Session Ċ import Ġkotlin . random . Random Ċ Ċ @ RunWith ( Android JUnit 4 :: class ) Ċ @ Large Test Ċ @ Ignore Ċ class ĠSecurity Bootstrap Test Ġ: ĠVerification TestBase () Ġ{ ĊĊĠĠĠ Ġvar Ġexisting Session : ĠSession ? Ġ= Ġnull ĊĊĠĠĠ Ġ@ get : Rule ĊĠĠĠ Ġval Ġactivity Rule Ġ= ĠActivity Scenario Rule ( MainActivity :: class . java ) ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun Ġcreate Session With Cross Signing () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġmatrix Ġ= Ġget Matrix Instance () ĊĠĠĠĠĠĠĠ Ġval ĠuserName Ġ= Ġ" foobar _${ Random . next Long () }" ĊĠĠĠĠĠĠĠ Ġexisting Session Ġ= Ġcreate Account And Sync ( matrix , ĠuserName , Ġpassword , Ġtrue ) ĊĠĠĠĠĠĠĠ Ġstub All External Intent s () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġstub All External Intent s () Ġ{ ĊĠĠĠĠĠĠĠ Ġ// ĠBy Ġdefault ĠE sp ress o ĠInt ents Ġdoes Ġnot Ġstub Ġany ĠInt ents . ĠStub bing Ġneeds Ġto Ġbe Ġsetup Ġbefore ĊĠĠĠĠĠĠĠ Ġ// Ġevery Ġtest Ġrun . ĠIn Ġthis Ġcase Ġall Ġexternal ĠInt ents Ġwill Ġbe Ġblocked . ĊĠĠĠĠĠĠĠ ĠInt ents . init () ĊĠĠĠĠĠĠĠ Ġint ending ( not ( is Internal ())). respond With ( Activity Result ( Activity . RESULT _ OK , Ġnull )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Basic Bootstrap () Ġ{ ĊĠĠĠĠĠĠĠ Ġval ĠuserId : ĠString Ġ= Ġexisting Session !!. my UserId ĊĊĠĠĠĠĠĠĠ Ġui TestBase . login ( userId Ġ= ĠuserId , Ġpassword Ġ= Ġpassword , Ġhome Server Url Ġ= Ġhome Server Url ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠThread . sleep ( 6 0 0 0 ) ĊĠĠĠĠĠĠĠ Ġwith Id ling Resource ( activity Id ling Resource ( Home Activity :: class . java )) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . room List Container )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. check ( matches ( is Displayed ())) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. perform ( close Soft Keyboard ()) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġval Ġactivity Ġ= ĠE sp ress o Helper . getCurrent Activity () !! ĊĠĠĠĠĠĠĠ Ġval Ġui Session Ġ= Ġ( activity Ġas ĠHome Activity ). active Session Holder . getActive Session () ĊĊĠĠĠĠĠĠĠ Ġwith Id ling Resource ( initial Sync Id ling Resource ( ui Session )) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . room List Container )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. check ( matches ( is Displayed ())) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġactivity . navigator . open 4 S Setup ( activity , ĠSetup Mode . NORMAL ) ĊĊĠĠĠĠĠĠĠ ĠThread . sleep ( 1 0 0 0 ) ĊĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . bootstrap Setup Secure Use Security Key )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. check ( matches ( is Displayed ())) ĊĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . bootstrap Setup Secure Use Security Pass phrase )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. check ( matches ( is Displayed ())) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. perform ( click ()) ĊĊĠĠĠĠĠĠĠ Ġon View ( is Root ()) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. perform ( waitFor View ( with Text ( R . string . bootstrap _ info _ text _ 2 ))) ĊĊĠĠĠĠĠĠĠ Ġ// Ġtest Ġback ĊĠĠĠĠĠĠĠ Ġon View ( is Root ()). perform ( press Back ()) ĊĊĠĠĠĠĠĠĠ ĠThread . sleep ( 1 0 0 0 ) ĊĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . bootstrap Setup Secure Use Security Key )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. check ( matches ( is Displayed ())) ĊĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . bootstrap Setup Secure Use Security Pass phrase )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. check ( matches ( is Displayed ())) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. perform ( click ()) ĊĊĠĠĠĠĠĠĠ Ġon View ( is Root ()) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. perform ( waitFor View ( with Text ( R . string . bootstrap _ info _ text _ 2 ))) ĊĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . ssss _ pass phrase _ enter _ edit text )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. perform ( type Text (" person Ġwoman Ġman Ġcamera Ġtv ")) ĊĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . bootstrap Submit )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. perform ( close Soft Keyboard (), Ġclick ()) ĊĊĠĠĠĠĠĠĠ Ġ// Ġtest Ġbad Ġpass ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . ssss _ pass phrase _ enter _ edit text )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. perform ( type Text (" person Ġwoman Ġman Ġc mer a Ġtv ")) ĊĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . bootstrap Submit )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. perform ( close Soft Keyboard (), Ġclick ()) ĊĊĠĠĠĠĠĠĠ Ġon View ( with Text ( R . string . pass phrase _ pass phrase _ does _ not _ match )). check ( matches ( is Displayed ())) ĊĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . ssss _ pass phrase _ enter _ edit text )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. perform ( replace Text (" person Ġwoman Ġman Ġcamera Ġtv ")) ĊĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . bootstrap Submit )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. perform ( close Soft Keyboard (), Ġclick ()) ĊĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . bottom Sheet ScrollView )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. perform ( waitFor View ( with Text ( R . string . bottom _ sheet _ save _ your _ recovery _ key _ content ))) ĊĊĠĠĠĠĠĠĠ Ġint ending ( has Action ( Intent . ACTION _ SEND )). respond With ( Activity Result ( Activity . RESULT _ OK , Ġnull )) ĊĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . recovery Copy )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. perform ( click ()) ĊĊĠĠĠĠĠĠĠ Ġ// ĠDis miss Ġdialog ĊĠĠĠĠĠĠĠ Ġon View ( with Text ( R . string . ok )). in Root ( Root Matchers . is Dialog ()). perform ( click ()) ĊĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . bottom Sheet ScrollView )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. perform ( waitFor View ( with Text ( R . string . bottom _ sheet _ save _ your _ recovery _ key _ content ))) ĊĊĠĠĠĠĠĠĠ Ġon View ( with Text ( R . string ._ continue )). perform ( click ()) ĊĊĠĠĠĠĠĠĠ Ġ// ĠAssert Ġthat Ġall Ġis Ġconfigured ĊĠĠĠĠĠĠĠ Ġassert ( ui Session . crypto Service (). cross Signing Service (). is Cross Signing Initialized ()) ĊĠĠĠĠĠĠĠ Ġassert ( ui Session . crypto Service (). cross Signing Service (). can Cross Sign ()) ĊĠĠĠĠĠĠĠ Ġassert ( ui Session . crypto Service (). cross Signing Service (). all Private Keys Known ()) ĊĠĠĠĠĠĠĠ Ġassert ( ui Session . crypto Service (). keys Backup Service (). isEnabled ()) ĊĠĠĠĠĠĠĠ Ġassert ( ui Session . crypto Service (). keys Backup Service (). current Backup Version Ġ!= Ġnull ) ĊĠĠĠĠĠĠĠ Ġassert ( ui Session . shared Secret Storage Service (). is Recovery Setup ()) ĊĠĠĠĠĠĠĠ Ġassert ( ui Session . shared Secret Storage Service (). is Me gol m Key In Backup ()) ĊĠĠĠ Ġ} Ċ } Ċ