@@ -2094,6 +2094,95 @@ public function testSetVersion() {
20942094 }
20952095
20962096 public function testGetAppsAllowlist () {
2097+ $ this ->config ->method ('getSystemValueString ' )
2098+ ->willReturnCallback (function ($ key , $ default ) {
2099+ if ($ key === 'version ' ) {
2100+ return '11.0.0.2 ' ;
2101+ } else {
2102+ return $ default ;
2103+ }
2104+ });
2105+ $ this ->config ->method ('getSystemValue ' )
2106+ ->willReturnCallback (function ($ key , $ default ) {
2107+ if ($ key === 'appsallowlist ' ) {
2108+ return ['contacts ' ];
2109+ }
2110+ return $ default ;
2111+ });
2112+ $ this ->config ->method ('getAppValue ' )
2113+ ->willReturnCallback (function ($ app , $ key , $ default ) {
2114+ if ($ app === 'support ' && $ key === 'subscription_key ' ) {
2115+ return 'subscription-key ' ;
2116+ }
2117+ return $ default ;
2118+ });
2119+ $ this ->config
2120+ ->method ('getSystemValueBool ' )
2121+ ->willReturnArgument (1 );
2122+
2123+ $ file = $ this ->createMock (ISimpleFile::class);
2124+ $ folder = $ this ->createMock (ISimpleFolder::class);
2125+ $ folder
2126+ ->expects ($ this ->once ())
2127+ ->method ('getFile ' )
2128+ ->with ('apps.json ' )
2129+ ->willThrowException (new NotFoundException ());
2130+ $ folder
2131+ ->expects ($ this ->once ())
2132+ ->method ('newFile ' )
2133+ ->with ('apps.json ' )
2134+ ->willReturn ($ file );
2135+ $ this ->appData
2136+ ->expects ($ this ->once ())
2137+ ->method ('getFolder ' )
2138+ ->with ('/ ' )
2139+ ->willReturn ($ folder );
2140+ $ client = $ this ->createMock (IClient::class);
2141+ $ this ->clientService
2142+ ->expects ($ this ->once ())
2143+ ->method ('newClient ' )
2144+ ->willReturn ($ client );
2145+ $ response = $ this ->createMock (IResponse::class);
2146+ $ client
2147+ ->expects ($ this ->once ())
2148+ ->method ('get ' )
2149+ ->with ('https://apps.nextcloud.com/api/v1/apps.json ' , [
2150+ 'timeout ' => 60 ,
2151+ 'headers ' => [
2152+ 'X-NC-Subscription-Key ' => 'subscription-key ' ,
2153+ ],
2154+ ])
2155+ ->willReturn ($ response );
2156+ $ response
2157+ ->expects ($ this ->once ())
2158+ ->method ('getBody ' )
2159+ ->willReturn (self ::$ responseJson );
2160+ $ response ->method ('getHeader ' )
2161+ ->with ($ this ->equalTo ('ETag ' ))
2162+ ->willReturn ('"myETag" ' );
2163+ $ this ->timeFactory
2164+ ->expects ($ this ->once ())
2165+ ->method ('getTime ' )
2166+ ->willReturn (1234 );
2167+
2168+ $ this ->registry
2169+ ->expects ($ this ->exactly (2 ))
2170+ ->method ('delegateHasValidSubscription ' )
2171+ ->willReturn (true );
2172+
2173+ $ file
2174+ ->expects ($ this ->once ())
2175+ ->method ('putContent ' );
2176+ $ file
2177+ ->method ('getContent ' )
2178+ ->willReturn (json_encode (self ::$ expectedResponse ));
2179+
2180+ $ apps = array_values ($ this ->fetcher ->get ());
2181+ $ this ->assertEquals (count ($ apps ), 1 );
2182+ $ this ->assertEquals ($ apps [0 ]['id ' ], 'contacts ' );
2183+ }
2184+
2185+ public function testGetAppsAllowlistCustomAppstore (): void {
20972186 $ this ->config ->method ('getSystemValueString ' )
20982187 ->willReturnCallback (function ($ key , $ default ) {
20992188 if ($ key === 'version ' ) {
@@ -2142,7 +2231,9 @@ public function testGetAppsAllowlist() {
21422231 $ client
21432232 ->expects ($ this ->once ())
21442233 ->method ('get ' )
2145- ->with ('https://custom.appsstore.endpoint/api/v1/apps.json ' )
2234+ ->with ('https://custom.appsstore.endpoint/api/v1/apps.json ' , [
2235+ 'timeout ' => 60 ,
2236+ ])
21462237 ->willReturn ($ response );
21472238 $ response
21482239 ->expects ($ this ->once ())
@@ -2157,7 +2248,7 @@ public function testGetAppsAllowlist() {
21572248 ->willReturn (1234 );
21582249
21592250 $ this ->registry
2160- ->expects ($ this ->exactly (2 ))
2251+ ->expects ($ this ->exactly (1 ))
21612252 ->method ('delegateHasValidSubscription ' )
21622253 ->willReturn (true );
21632254
0 commit comments