...

Source file src/github.com/ory/fosite/fosite_test.go

Documentation: github.com/ory/fosite

     1  /*
     2   * Copyright © 2015-2018 Aeneas Rekkas <aeneas+oss@aeneas.io>
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   *
    16   * @author		Aeneas Rekkas <aeneas+oss@aeneas.io>
    17   * @copyright 	2015-2018 Aeneas Rekkas <aeneas+oss@aeneas.io>
    18   * @license 	Apache-2.0
    19   *
    20   */
    21  
    22  package fosite_test
    23  
    24  import (
    25  	"testing"
    26  
    27  	"github.com/stretchr/testify/assert"
    28  	"github.com/stretchr/testify/require"
    29  
    30  	. "github.com/ory/fosite"
    31  	"github.com/ory/fosite/handler/oauth2"
    32  )
    33  
    34  func TestAuthorizeEndpointHandlers(t *testing.T) {
    35  	h := &oauth2.AuthorizeExplicitGrantHandler{}
    36  	hs := AuthorizeEndpointHandlers{}
    37  	hs.Append(h)
    38  	hs.Append(h)
    39  	hs.Append(&oauth2.AuthorizeExplicitGrantHandler{})
    40  	assert.Len(t, hs, 1)
    41  	assert.Equal(t, hs[0], h)
    42  }
    43  
    44  func TestTokenEndpointHandlers(t *testing.T) {
    45  	h := &oauth2.AuthorizeExplicitGrantHandler{}
    46  	hs := TokenEndpointHandlers{}
    47  	hs.Append(h)
    48  	hs.Append(h)
    49  	// do some crazy type things and make sure dupe detection works
    50  	var f interface{} = &oauth2.AuthorizeExplicitGrantHandler{}
    51  	hs.Append(&oauth2.AuthorizeExplicitGrantHandler{})
    52  	hs.Append(f.(TokenEndpointHandler))
    53  	require.Len(t, hs, 1)
    54  	assert.Equal(t, hs[0], h)
    55  }
    56  
    57  func TestAuthorizedRequestValidators(t *testing.T) {
    58  	h := &oauth2.CoreValidator{}
    59  	hs := TokenIntrospectionHandlers{}
    60  	hs.Append(h)
    61  	hs.Append(h)
    62  	hs.Append(&oauth2.CoreValidator{})
    63  	require.Len(t, hs, 1)
    64  	assert.Equal(t, hs[0], h)
    65  }
    66  
    67  func TestMinParameterEntropy(t *testing.T) {
    68  	f := Fosite{}
    69  	assert.Equal(t, MinParameterEntropy, f.GetMinParameterEntropy())
    70  
    71  	f = Fosite{
    72  		MinParameterEntropy: 42,
    73  	}
    74  	assert.Equal(t, 42, f.GetMinParameterEntropy())
    75  }
    76  

View as plain text