github.com/weaviate/weaviate@v1.24.6/usecases/config/authentication_test.go (about)

     1  //                           _       _
     2  // __      _____  __ ___   ___  __ _| |_ ___
     3  // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
     4  //  \ V  V /  __/ (_| |\ V /| | (_| | ||  __/
     5  //   \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
     6  //
     7  //  Copyright © 2016 - 2024 Weaviate B.V. All rights reserved.
     8  //
     9  //  CONTACT: hello@weaviate.io
    10  //
    11  
    12  package config
    13  
    14  import (
    15  	"fmt"
    16  	"testing"
    17  
    18  	"github.com/stretchr/testify/assert"
    19  )
    20  
    21  func TestConfig_Authentication(t *testing.T) {
    22  	t.Run("no auth selected", func(t *testing.T) {
    23  		auth := Authentication{}
    24  		expected := fmt.Errorf("no authentication scheme configured, you must select at least one")
    25  
    26  		err := auth.Validate()
    27  
    28  		assert.Equal(t, expected, err)
    29  	})
    30  
    31  	t.Run("only anonymous selected", func(t *testing.T) {
    32  		auth := Authentication{
    33  			AnonymousAccess: AnonymousAccess{
    34  				Enabled: true,
    35  			},
    36  		}
    37  
    38  		err := auth.Validate()
    39  
    40  		assert.Nil(t, err, "should not error")
    41  	})
    42  
    43  	t.Run("only oidc selected", func(t *testing.T) {
    44  		auth := Authentication{
    45  			OIDC: OIDC{
    46  				Enabled: true,
    47  			},
    48  		}
    49  
    50  		err := auth.Validate()
    51  
    52  		assert.Nil(t, err, "should not error")
    53  	})
    54  
    55  	t.Run("oidc and anonymous enabled together", func(t *testing.T) {
    56  		// this might seem counter-intuitive at first, but this makes a lot of
    57  		// sense when you consider the authorization strategies: for example we
    58  		// could allow reads for everyone, but only explicitly authenticated users
    59  		// may write
    60  		auth := Authentication{
    61  			OIDC: OIDC{
    62  				Enabled: true,
    63  			},
    64  			AnonymousAccess: AnonymousAccess{
    65  				Enabled: true,
    66  			},
    67  		}
    68  
    69  		err := auth.Validate()
    70  
    71  		assert.Nil(t, err, "should not error")
    72  	})
    73  }