github.com/mysteriumnetwork/node@v0.0.0-20240516044423-365054f76801/e2e/ui_test.go (about) 1 /* 2 * Copyright (C) 2019 The "MysteriumNetwork/node" Authors. 3 * 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation, either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 package e2e 19 20 import ( 21 "encoding/base64" 22 "net/http" 23 "strings" 24 "testing" 25 "time" 26 27 "github.com/koron/go-ssdp" 28 "github.com/oleksandr/bonjour" 29 "github.com/stretchr/testify/assert" 30 ) 31 32 func TestLANDiscoverySSDP(t *testing.T) { 33 services, err := ssdp.Search(ssdp.All, 1, "") 34 assert.NoError(t, err) 35 for _, service := range services { 36 if service.Type == "upnp:rootdevice" && strings.Contains(service.Server, "UPnP/1.1 node/") { 37 resp, err := http.Get(service.Location) 38 assert.NoError(t, err) 39 assert.Equal(t, http.StatusOK, resp.StatusCode) 40 return 41 } 42 } 43 44 assert.Fail(t, "No SSDP service found") 45 } 46 47 func TestLANDiscoveryBonjour(t *testing.T) { 48 resolver, err := bonjour.NewResolver(nil) 49 assert.NoError(t, err) 50 defer func() { resolver.Exit <- true }() 51 52 results := make(chan *bonjour.ServiceEntry) 53 go resolver.Browse("_mysterium-node._tcp", "", results) 54 55 for { 56 select { 57 case <-time.After(3 * time.Second): 58 assert.Fail(t, "No Bonjour service found") 59 return 60 case <-results: 61 return 62 } 63 } 64 } 65 66 func TestBuiltinUIAccessible(t *testing.T) { 67 req, err := http.NewRequest("GET", "http://"+*providerTequilapiHost+":4449", nil) 68 assert.NoError(t, err) 69 req.Header.Add("Authorization", "Basic "+base64.StdEncoding.EncodeToString([]byte("myst:mystberry"))) 70 resp, err := http.DefaultClient.Do(req) 71 assert.NoError(t, err) 72 assert.Equal(t, http.StatusOK, resp.StatusCode) 73 }