github.com/jxgolibs/go-oauth2-server@v1.0.1/oauth/scope_test.go (about)

     1  package oauth_test
     2  
     3  import (
     4  	"github.com/RichardKnop/go-oauth2-server/oauth"
     5  	"github.com/stretchr/testify/assert"
     6  )
     7  
     8  func (suite *OauthTestSuite) TestGetScope() {
     9  	var (
    10  		scope string
    11  		err   error
    12  	)
    13  
    14  	// When the requested scope is an empty string,
    15  	// the default scope should be returned
    16  	scope, err = suite.service.GetScope("")
    17  	assert.Nil(suite.T(), err)
    18  	assert.Equal(suite.T(), "read", scope)
    19  
    20  	// When the requested scope is valid, it should be returned
    21  	scope, err = suite.service.GetScope("read read_write")
    22  	assert.Nil(suite.T(), err)
    23  	assert.Equal(suite.T(), "read read_write", scope)
    24  
    25  	// When the requested scope is invalid, an error should be returned
    26  	_, err = suite.service.GetScope("read_write bogus")
    27  	if assert.NotNil(suite.T(), err) {
    28  		assert.Equal(suite.T(), oauth.ErrInvalidScope, err)
    29  	}
    30  }
    31  
    32  func (suite *OauthTestSuite) TestGetDefaultScope() {
    33  	assert.Equal(suite.T(), "read", suite.service.GetDefaultScope())
    34  }
    35  
    36  func (suite *OauthTestSuite) TestScopeExists() {
    37  	assert.True(suite.T(), suite.service.ScopeExists("read read_write"))
    38  
    39  	assert.False(suite.T(), suite.service.ScopeExists("read_write bogus"))
    40  }