Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions ovh/consumer_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type CkValidationState struct {
type CkRequest struct {
client *Client
AccessRules []AccessRule `json:"accessRules"`
Redirection string `json:"redirection,omitempty"`
}

func (ck *CkValidationState) String() string {
Expand All @@ -58,6 +59,15 @@ func (c *Client) NewCkRequest() *CkRequest {
}
}

// NewCkRequestWithRedirection helps create a new ck request with a redirect URL
func (c *Client) NewCkRequestWithRedirection(redirection string) *CkRequest {
return &CkRequest{
client: c,
AccessRules: []AccessRule{},
Redirection: redirection,
}
}

// AddRule adds a new rule to the ckRequest
func (ck *CkRequest) AddRule(method, path string) {
ck.AccessRules = append(ck.AccessRules, AccessRule{
Expand Down
18 changes: 15 additions & 3 deletions ovh/consumer_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

// Common helpers are in ovh_test.go

func TestNewCkReqest(t *testing.T) {
func TestNewCkRequest(t *testing.T) {
const expectedRequest = `{"accessRules":[{"method":"GET","path":"/me"},{"method":"GET","path":"/xdsl/*"}]}`

// Init test
Expand Down Expand Up @@ -50,7 +50,7 @@ func TestNewCkReqest(t *testing.T) {
ensureHeaderPresent(t, InputRequest, "X-Ovh-Application", MockApplicationKey)
}

func TestInvalidCkReqest(t *testing.T) {
func TestInvalidCkRequest(t *testing.T) {
// Init test
var InputRequest *http.Request
var InputRequestBody string
Expand Down Expand Up @@ -129,7 +129,7 @@ func TestAddRules(t *testing.T) {
}
}

func TestCkReqestString(t *testing.T) {
func TestCkRequestString(t *testing.T) {
ckValidationState := &CkValidationState{
ConsumerKey: "ck",
State: "pending",
Expand All @@ -143,3 +143,15 @@ func TestCkReqestString(t *testing.T) {
t.Errorf("expected %q, got %q", expected, got)
}
}

func TestCkRequestRedirection(t *testing.T) {
client, _ := NewClient("endpoint", "appKey", "appSecret", "consumerKey")

redirection := "http://localhost/api/auth/callback?token=123456"

ckRequest := client.NewCkRequestWithRedirection(redirection)

if ckRequest.Redirection != redirection {
t.Fatalf("NewCkRequestWithRedirection should set ckRequest.Redirection")
}
}