featurebase/server/server_internal_test.go
reesporte cf2410fea6 addresses multiple authn/z tickets
* fb-998 - authn/z enabled in handlers (kitchen-sink ticket)
    - authorization is enabled through the use of a bearer token (using header "Authorization")
    - authorization may occur through the use of an "Authorization" header or "molecula-chip" cookie
    - ui is updated for changes to handler
* fb-1131 - protect grpc endpoints
    - GRPC endpoints now check authorization if auth is enabled
* fb-1129 - inter-node communication
    - the following endpoints use the secretKey for authentication:
        - /internal/cluster/message: POST
        - /internal/translate/data: GET, POST

* added test to api_test.go (TestAuth_MultiNode) testing various auth/permissions stuff on a multi-node cluster

not included:
    - fb-1130 - filter response of endpoints
    - fb-1109 - improved audit logging

@jaffee [are you not entertained](https://www.youtube.com/watch?v=mutgotxrcqg)

Co-authored-by: souhailanoor <90720110+souhailanoor@users.noreply.github.com>
Co-authored-by: tgruben <tgruben@gmail.com>
Co-authored-by: 54mir <48686912+54mir@users.noreply.github.com>
Co-authored-by: kcrodgers24 <49999391+kcrodgers24@users.noreply.github.com>
2022-01-14 12:31:32 -06:00

40 lines
764 B
Go

package server
import (
"fmt"
"testing"
)
// unit tests for internal functions
func TestIsAllowed(t *testing.T) {
cases := []struct {
requested []string
allowed []string
expected bool
}{
{
requested: []string{"a", "b", "c"},
allowed: []string{"a", "b", "c", "d", "e"},
expected: true,
},
{
requested: []string{"a", "b", "c", "f"},
allowed: []string{"a", "b", "c", "d", "e"},
expected: false,
},
{
requested: []string{"a", "b", "c"},
allowed: []string{},
expected: false,
},
}
for i, test := range cases {
t.Run(fmt.Sprint(i), func(t *testing.T) {
if res := isAllowed(test.requested, test.allowed); res != test.expected {
t.Errorf("expected %v, got %v", test.expected, res)
}
})
}
}