mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 04:47:18 +00:00
d77c298ec6
* jwt access token impl * use secret or jwt * rename * separate method for splitting auth * usage update * Update beacon-chain/flags/base.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update beacon-chain/node/node.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * make things work * removed unused code * better, more flexible authorization * move types and function to proper packages * fix checking if endpoint is not set * fix existing tests * rename Endpoint field to Url * Tests for HttpEndpoint * better bearer auth * tests for endpoint utils * fix endpoint registration * fix test build * move endpoint parsing to powchain * Revert "fix existing tests" This reverts commit ceab192e6a78c106cf4e16a1bdf5399752a39890. * fix field name in tests * gzl * add httputils dependency * remove httputils dependency * fix compilation issue in blockchain service test * correct endpoint fallback function and tests * gzl * remove pointer from currHttpEndpoint * allow whitespace in auth string * endpoint equality * correct one auth data Equals test case * remove pointer receiver Co-authored-by: Radosław Kapka <rkapka@wp.pl> Co-authored-by: Raul Jordan <raul@prysmaticlabs.com>
75 lines
2.8 KiB
Go
75 lines
2.8 KiB
Go
package powchain
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/prysmaticlabs/prysm/shared/httputils/authorizationmethod"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
|
logTest "github.com/sirupsen/logrus/hooks/test"
|
|
)
|
|
|
|
func TestHttpEndpoint(t *testing.T) {
|
|
hook := logTest.NewGlobal()
|
|
url := "http://test"
|
|
|
|
t.Run("URL", func(t *testing.T) {
|
|
endpoint := HttpEndpoint(url)
|
|
assert.Equal(t, url, endpoint.Url)
|
|
assert.Equal(t, authorizationmethod.None, endpoint.Auth.Method)
|
|
})
|
|
t.Run("URL with separator", func(t *testing.T) {
|
|
endpoint := HttpEndpoint(url + ",")
|
|
assert.Equal(t, url, endpoint.Url)
|
|
assert.Equal(t, authorizationmethod.None, endpoint.Auth.Method)
|
|
})
|
|
t.Run("URL with whitespace", func(t *testing.T) {
|
|
endpoint := HttpEndpoint(" " + url + " ,")
|
|
assert.Equal(t, url, endpoint.Url)
|
|
assert.Equal(t, authorizationmethod.None, endpoint.Auth.Method)
|
|
})
|
|
t.Run("Basic auth", func(t *testing.T) {
|
|
endpoint := HttpEndpoint(url + ",Basic username:password")
|
|
assert.Equal(t, url, endpoint.Url)
|
|
assert.Equal(t, authorizationmethod.Basic, endpoint.Auth.Method)
|
|
assert.Equal(t, "dXNlcm5hbWU6cGFzc3dvcmQ=", endpoint.Auth.Value)
|
|
})
|
|
t.Run("Basic auth with whitespace", func(t *testing.T) {
|
|
endpoint := HttpEndpoint(url + ", Basic username:password ")
|
|
assert.Equal(t, url, endpoint.Url)
|
|
assert.Equal(t, authorizationmethod.Basic, endpoint.Auth.Method)
|
|
assert.Equal(t, "dXNlcm5hbWU6cGFzc3dvcmQ=", endpoint.Auth.Value)
|
|
})
|
|
t.Run("Basic auth with incorrect format", func(t *testing.T) {
|
|
hook.Reset()
|
|
endpoint := HttpEndpoint(url + ",Basic username:password foo")
|
|
assert.Equal(t, url, endpoint.Url)
|
|
assert.Equal(t, authorizationmethod.None, endpoint.Auth.Method)
|
|
assert.LogsContain(t, hook, "Skipping authorization")
|
|
})
|
|
t.Run("Bearer auth", func(t *testing.T) {
|
|
endpoint := HttpEndpoint(url + ",Bearer token")
|
|
assert.Equal(t, url, endpoint.Url)
|
|
assert.Equal(t, authorizationmethod.Bearer, endpoint.Auth.Method)
|
|
assert.Equal(t, "token", endpoint.Auth.Value)
|
|
})
|
|
t.Run("Bearer auth with whitespace", func(t *testing.T) {
|
|
endpoint := HttpEndpoint(url + ", Bearer token ")
|
|
assert.Equal(t, url, endpoint.Url)
|
|
assert.Equal(t, authorizationmethod.Bearer, endpoint.Auth.Method)
|
|
assert.Equal(t, "token", endpoint.Auth.Value)
|
|
})
|
|
t.Run("Bearer auth with incorrect format", func(t *testing.T) {
|
|
hook.Reset()
|
|
endpoint := HttpEndpoint(url + ",Bearer token foo")
|
|
assert.Equal(t, url, endpoint.Url)
|
|
assert.Equal(t, authorizationmethod.None, endpoint.Auth.Method)
|
|
assert.LogsContain(t, hook, "Skipping authorization")
|
|
})
|
|
t.Run("Too many separators", func(t *testing.T) {
|
|
endpoint := HttpEndpoint(url + ",Bearer token,foo")
|
|
assert.Equal(t, url, endpoint.Url)
|
|
assert.Equal(t, authorizationmethod.None, endpoint.Auth.Method)
|
|
assert.LogsContain(t, hook, "Skipping authorization")
|
|
})
|
|
}
|