33package e2e_grpc_test
44
55import (
6+ "os"
67 "strings"
78 "testing"
89)
@@ -23,13 +24,6 @@ func runSuccess(t *testing.T, args ...string) string {
2324 return runLiveJnicli (t , args ... )
2425}
2526
26- // runExpectErr runs jnicli and asserts non-zero exit-code.
27- // Returns combined output for further assertions.
28- func runExpectErr (t * testing.T , args ... string ) string {
29- t .Helper ()
30- return runLiveJnicliExpectError (t , args ... )
31- }
32-
3327// assertContains fails the test if substr is not found in s.
3428func assertContains (t * testing.T , s , substr string ) {
3529 t .Helper ()
@@ -348,8 +342,7 @@ func TestE2E_Services_Auth(t *testing.T) {
348342func TestE2E_Services_Download_SecurityException (t * testing.T ) {
349343 skipIfNoEmulator (t )
350344 t .Run ("GetMimeTypeForDownloadedFile" , func (t * testing.T ) {
351- out := runExpectErr (t , "download" , "manager" , "get-mime-type-for-downloaded-file" , "--arg0" , "1" )
352- assertContains (t , out , "SecurityException" )
345+ assertSecurityExceptionOrSuccess (t , "download" , "manager" , "get-mime-type-for-downloaded-file" , "--arg0" , "1" )
353346 })
354347}
355348
@@ -358,21 +351,50 @@ func TestE2E_Services_Download_SecurityException(t *testing.T) {
358351func TestE2E_Services_Blob_SecurityException (t * testing.T ) {
359352 skipIfNoEmulator (t )
360353 t .Run ("GetRemainingLeaseQuotaBytes" , func (t * testing.T ) {
361- out := runExpectErr (t , "blob" , "store-manager" , "get-remaining-lease-quota-bytes" )
362- assertContains (t , out , "SecurityException" )
354+ assertSecurityExceptionOrSuccess (t , "blob" , "store-manager" , "get-remaining-lease-quota-bytes" )
363355 })
364356}
365357
366358func TestE2E_Services_Location_SecurityException (t * testing.T ) {
367359 skipIfNoEmulator (t )
368360 t .Run ("GetLastKnownLocation_GPS" , func (t * testing.T ) {
369- out := runExpectErr (t , "location" , "manager" , "get-last-known-location" , "--arg0" , "gps" )
370- assertContains (t , out , "SecurityException" )
361+ assertSecurityExceptionOrSuccess (t , "location" , "manager" , "get-last-known-location" , "--arg0" , "gps" )
371362 })
372363}
373364
374365func TestE2E_Services_Notification_SecurityException (t * testing.T ) {
375- t .Skip ("get-notification-channels RPC no longer exists; notification service covered by working tests" )
366+ skipIfNoEmulator (t )
367+ t .Run ("GetNotificationChannels" , func (t * testing.T ) {
368+ assertSecurityExceptionOrSuccess (t , "notification" , "manager" , "get-notification-channels" )
369+ })
370+ }
371+
372+ // assertSecurityExceptionOrSuccess verifies that a command either fails
373+ // with SecurityException (when server lacks permissions, e.g. app_process
374+ // mode) or succeeds (when server has the required permissions, e.g. APK
375+ // mode with grants).
376+ func assertSecurityExceptionOrSuccess (t * testing.T , args ... string ) {
377+ t .Helper ()
378+ out := runLiveJnicliAllowError (t , args ... )
379+ if out .err != nil {
380+ assertContains (t , out .combined , "SecurityException" )
381+ }
382+ }
383+
384+ type cmdResult struct {
385+ combined string
386+ err error
387+ }
388+
389+ func runLiveJnicliAllowError (t * testing.T , args ... string ) cmdResult {
390+ t .Helper ()
391+ addr := os .Getenv ("JNICTL_E2E_ADDR" )
392+ fullArgs := append ([]string {"--addr" , addr , "--insecure" }, mtlsFlags ()... )
393+ fullArgs = append (fullArgs , args ... )
394+
395+ cmd := jnicliCommand (fullArgs ... )
396+ out , err := cmd .CombinedOutput ()
397+ return cmdResult {combined : string (out ), err : err }
376398}
377399
378400// ---------- Unimplemented services ----------
0 commit comments