@@ -8,8 +8,10 @@ import (
8
8
"encoding/hex"
9
9
"fmt"
10
10
"io/ioutil"
11
+ "net/http"
11
12
"strings"
12
13
"testing"
14
+ "time"
13
15
14
16
"github.com/btcsuite/btcutil"
15
17
"github.com/lightninglabs/faraday/frdrpc"
@@ -27,6 +29,13 @@ import (
27
29
"gopkg.in/macaroon.v2"
28
30
)
29
31
32
+ const (
33
+ // indexHtmlMarker is a string that appears in the rendered index.html
34
+ // file of the main UI. This is created by Webpack and should be fairly
35
+ // stable.
36
+ indexHtmlMarker = "webpackJsonplightning-terminal"
37
+ )
38
+
30
39
// requestFn is a function type for a helper function that makes a daemon
31
40
// specific request and returns the response and error for it. This is used to
32
41
// abstract away the lnd/faraday/loop/pool specific gRPC code from the actual
52
61
InsecureSkipVerify : true ,
53
62
},
54
63
}
64
+ client = http.Client {
65
+ Transport : transport ,
66
+ Timeout : 1 * time .Second ,
67
+ }
55
68
56
69
lndRequestFn = func (ctx context.Context ,
57
70
c grpc.ClientConnInterface ) (proto.Message , error ) {
@@ -240,6 +253,10 @@ func testModeIntegrated(net *NetworkHarness, t *harnessTest) {
240
253
})
241
254
}
242
255
})
256
+
257
+ t .t .Run ("UI index page fallback" , func (tt * testing.T ) {
258
+ runIndexPageCheck (tt , net .Alice .Cfg .LitAddr ())
259
+ })
243
260
}
244
261
245
262
// runCertificateCheck checks that the TLS certificates presented to clients are
@@ -375,6 +392,40 @@ func runUIPasswordCheck(t *testing.T, hostPort, tlsCertPath, uiPassword string,
375
392
require .Contains (t , string (json ), successContent )
376
393
}
377
394
395
+ // runIndexPageCheck makes sure the index page is returned correctly.
396
+ func runIndexPageCheck (t * testing.T , hostPort string ) {
397
+ body , err := getURL (fmt .Sprintf ("https://%s/index.html" , hostPort ))
398
+ require .NoError (t , err )
399
+ require .Contains (t , body , indexHtmlMarker )
400
+
401
+ // The UI implements "virtual" pages by using the browser history API.
402
+ // Any URL that looks like a directory should fall back to the main
403
+ // index.html file as well.
404
+ body , err = getURL (fmt .Sprintf ("https://%s/loop" , hostPort ))
405
+ require .NoError (t , err )
406
+ require .Contains (t , body , indexHtmlMarker )
407
+ }
408
+
409
+ // getURL retrieves the body of a given URL, ignoring any TLS certificate the
410
+ // server might present.
411
+ func getURL (url string ) (string , error ) {
412
+ resp , err := client .Get (url )
413
+ if err != nil {
414
+ return "" , err
415
+ }
416
+
417
+ defer func () {
418
+ _ = resp .Body .Close ()
419
+ }()
420
+
421
+ body , err := ioutil .ReadAll (resp .Body )
422
+ if err != nil {
423
+ return "" , err
424
+ }
425
+
426
+ return string (body ), nil
427
+ }
428
+
378
429
// getServerCertificates returns the TLS certificates that a server presents to
379
430
// clients.
380
431
func getServerCertificates (hostPort string ) ([]* x509.Certificate , error ) {
0 commit comments