2020-02-07 16:36:28 +00:00
|
|
|
// Copyright (C) 2020 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package admin_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
|
|
|
|
"storj.io/common/testcontext"
|
|
|
|
"storj.io/storj/private/testplanet"
|
|
|
|
"storj.io/storj/satellite"
|
|
|
|
)
|
|
|
|
|
2020-02-07 17:24:58 +00:00
|
|
|
func TestBasic(t *testing.T) {
|
2020-02-07 16:36:28 +00:00
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1,
|
|
|
|
StorageNodeCount: 0,
|
|
|
|
UplinkCount: 0,
|
|
|
|
Reconfigure: testplanet.Reconfigure{
|
|
|
|
Satellite: func(log *zap.Logger, index int, config *satellite.Config) {
|
|
|
|
config.Admin.Address = "127.0.0.1:0"
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
sat := planet.Satellites[0]
|
|
|
|
address := sat.Admin.Admin.Listener.Addr()
|
|
|
|
|
2020-02-07 17:24:58 +00:00
|
|
|
t.Run("NoAccess", func(t *testing.T) {
|
|
|
|
response, err := http.Get("http://" + address.String())
|
|
|
|
require.NoError(t, err)
|
2020-02-07 16:36:28 +00:00
|
|
|
|
2020-02-07 17:24:58 +00:00
|
|
|
require.Equal(t, http.StatusForbidden, response.StatusCode)
|
|
|
|
require.NoError(t, response.Body.Close())
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("WrongAccess", func(t *testing.T) {
|
|
|
|
req, err := http.NewRequest(http.MethodGet, "http://"+address.String(), nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
req.Header.Set("Authorization", "wrong-key")
|
|
|
|
|
|
|
|
response, err := http.DefaultClient.Do(req)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
require.Equal(t, http.StatusForbidden, response.StatusCode)
|
|
|
|
require.NoError(t, response.Body.Close())
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("WithAccess", func(t *testing.T) {
|
|
|
|
req, err := http.NewRequest(http.MethodGet, "http://"+address.String(), nil)
|
|
|
|
require.NoError(t, err)
|
2020-08-13 13:40:05 +01:00
|
|
|
req.Header.Set("Authorization", planet.Satellites[0].Config.Console.AuthToken)
|
2020-02-07 17:24:58 +00:00
|
|
|
|
|
|
|
response, err := http.DefaultClient.Do(req)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// currently no main page so 404
|
|
|
|
require.Equal(t, http.StatusNotFound, response.StatusCode)
|
|
|
|
require.NoError(t, response.Body.Close())
|
|
|
|
})
|
2020-02-07 16:36:28 +00:00
|
|
|
})
|
|
|
|
}
|