Skip to content

Commit

Permalink
consent: Better defaults for consent denied errors (#1297)
Browse files Browse the repository at this point in the history
Closes #1285

Signed-off-by: Kevin Minehart <kmineh0151@gmail.com>
  • Loading branch information
kminehart authored and aeneasr committed Mar 13, 2019
1 parent 1aad679 commit 0fc875a
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 122 deletions.
16 changes: 6 additions & 10 deletions consent/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ import (
"github.com/ory/hydra/client"
)

const (
requestDeniedErrorName = "consent request denied"
)

// The response payload sent when accepting or rejecting a login or consent request.
//
// swagger:model completedRequest
Expand Down Expand Up @@ -54,20 +58,12 @@ type RequestDeniedError struct {

func (e *RequestDeniedError) toRFCError() *fosite.RFC6749Error {
if e.Name == "" {
e.Name = fosite.ErrInvalidRequest.Name
e.Name = requestDeniedErrorName
}

if e.Code == 0 {
e.Code = fosite.ErrInvalidRequest.Code
}
if e.Description == "" {
e.Description = fosite.ErrInvalidRequest.Description
}
if e.Hint == "" {
e.Hint = fosite.ErrInvalidRequest.Hint
}
if e.Debug == "" {
e.Debug = fosite.ErrInvalidRequest.Debug
}

return &fosite.RFC6749Error{
Name: e.Name,
Expand Down
54 changes: 54 additions & 0 deletions consent/types_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package consent

import (
"fmt"
"testing"

"github.com/ory/fosite"
"github.com/stretchr/testify/require"
)

func TestToRFCError(t *testing.T) {
for k, tc := range []struct {
input *RequestDeniedError
expect *fosite.RFC6749Error
}{
{
input: &RequestDeniedError{
Name: "not empty",
},
expect: &fosite.RFC6749Error{
Name: "not empty",
Description: "",
Code: fosite.ErrInvalidRequest.Code,
Debug: "",
},
},
{
input: &RequestDeniedError{
Name: "",
Description: "not empty",
},
expect: &fosite.RFC6749Error{
Name: requestDeniedErrorName,
Description: "not empty",
Code: fosite.ErrInvalidRequest.Code,
Debug: "",
},
},
{
input: &RequestDeniedError{},
expect: &fosite.RFC6749Error{
Name: requestDeniedErrorName,
Description: "",
Hint: "",
Code: fosite.ErrInvalidRequest.Code,
Debug: "",
},
},
} {
t.Run(fmt.Sprintf("case=%d", k), func(t *testing.T) {
require.EqualValues(t, tc.input.toRFCError(), tc.expect)
})
}
}
44 changes: 2 additions & 42 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,27 @@ module github.com/ory/hydra

require (
cloud.google.com/go v0.36.0 // indirect
dmitri.shuralyov.com/app/changes v0.0.0-20181114035150-5af16e21babb // indirect
dmitri.shuralyov.com/service/change v0.0.0-20190203163610-217368fe4577 // indirect
git.apache.org/thrift.git v0.12.0 // indirect
github.com/Shopify/sarama v1.21.0 // indirect
github.com/coreos/go-systemd v0.0.0-20190212144455-93d5ec2c7f76 // indirect
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/gliderlabs/ssh v0.1.3 // indirect
github.com/go-logfmt/logfmt v0.4.0 // indirect
github.com/go-sql-driver/mysql v1.4.0
github.com/gobuffalo/packd v0.0.0-20181029140631-cf76bd87a5a6 // indirect
github.com/gobwas/glob v0.2.3
github.com/gogo/protobuf v1.2.1 // indirect
github.com/golang/lint v0.0.0-20181217174547-8f45f776aaf1 // indirect
github.com/golang/mock v1.2.0
github.com/golang/protobuf v1.3.0 // indirect
github.com/golang/snappy v0.0.1 // indirect
github.com/google/pprof v0.0.0-20190226225141-b51a6544410d // indirect
github.com/googleapis/gax-go v2.0.2+incompatible // indirect
github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e // indirect
github.com/gorilla/context v1.1.1
github.com/gorilla/mux v1.7.0 // indirect
github.com/gorilla/securecookie v0.0.0-20160422134519-667fe4e3466a
github.com/gorilla/sessions v0.0.0-20160922145804-ca9ada445741
github.com/gregjones/httpcache v0.0.0-20190212212710-3befbb6ad0cc // indirect
github.com/grpc-ecosystem/grpc-gateway v1.7.0 // indirect
github.com/gtank/cryptopasta v0.0.0-20170601214702-1f550f6f2f69
github.com/imdario/mergo v0.0.0-20171009183408-7fe0c75c13ab
github.com/jmoiron/sqlx v0.0.0-20180614180643-0dae4fefe7c0
github.com/julienschmidt/httprouter v1.2.0
github.com/kisielk/errcheck v1.2.0 // indirect
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
github.com/lib/pq v1.0.0
github.com/meatballhat/negroni-logrus v0.0.0-20170801195057-31067281800f
github.com/mendsley/gojwk v0.0.0-20141217222730-4d5ec6e58103
github.com/microcosm-cc/bluemonday v1.0.2 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826
github.com/oleiade/reflections v1.0.0
github.com/opentracing/opentracing-go v1.0.2
github.com/openzipkin/zipkin-go v0.1.5 // indirect
github.com/ory/dockertest v3.3.2+incompatible
github.com/ory/fosite v0.29.0
github.com/ory/go-convenience v0.1.0
Expand All @@ -57,21 +39,6 @@ require (
github.com/prometheus/procfs v0.0.0-20190225181712-6ed1f7e10411 // indirect
github.com/rs/cors v1.6.0
github.com/rubenv/sql-migrate v0.0.0-20180704111356-ba2c6a7295c59448dbc195cef2f41df5163b3892
github.com/russross/blackfriday v2.0.0+incompatible // indirect
github.com/shurcooL/go v0.0.0-20190121191506-3fef8c783dec // indirect
github.com/shurcooL/gofontwoff v0.0.0-20181114050219-180f79e6909d // indirect
github.com/shurcooL/highlight_diff v0.0.0-20181222201841-111da2e7d480 // indirect
github.com/shurcooL/highlight_go v0.0.0-20181215221002-9d8641ddf2e1 // indirect
github.com/shurcooL/home v0.0.0-20190204141146-5c8ae21d4240 // indirect
github.com/shurcooL/htmlg v0.0.0-20190120222857-1e8a37b806f3 // indirect
github.com/shurcooL/httpfs v0.0.0-20181222201310-74dc9339e414 // indirect
github.com/shurcooL/issues v0.0.0-20190120000219-08d8dadf8acb // indirect
github.com/shurcooL/issuesapp v0.0.0-20181229001453-b8198a402c58 // indirect
github.com/shurcooL/notifications v0.0.0-20181111060504-bcc2b3082a7a // indirect
github.com/shurcooL/octicon v0.0.0-20181222203144-9ff1a4cf27f4 // indirect
github.com/shurcooL/reactions v0.0.0-20181222204718-145cd5e7f3d1 // indirect
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
github.com/shurcooL/webdavfs v0.0.0-20181215192745-5988b2d638f6 // indirect
github.com/sirupsen/logrus v1.3.0
github.com/spf13/cobra v0.0.3
github.com/spf13/viper v1.2.1
Expand All @@ -83,20 +50,13 @@ require (
github.com/ziutek/mymysql v1.5.4 // indirect
go.opencensus.io v0.19.0 // indirect
go.uber.org/atomic v1.3.2 // indirect
go4.org v0.0.0-20190218023631-ce4c26f7be8e // indirect
golang.org/x/build v0.0.0-20190227044025-202164ea31fc // indirect
golang.org/x/crypto v0.0.0-20190227175134-215aa809caaf
golang.org/x/exp v0.0.0-20190221220918-438050ddec5e // indirect
golang.org/x/crypto v0.0.0-20190228161510-8dd112bcdc25
golang.org/x/net v0.0.0-20190227022144-312bce6e941f // indirect
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421
golang.org/x/perf v0.0.0-20190124201629-844a5f5b46f4 // indirect
golang.org/x/sys v0.0.0-20190226215855-775f8194d0f9 // indirect
golang.org/x/tools v0.0.0-20190226205152-f727befe758c // indirect
golang.org/x/sys v0.0.0-20190305064518-30e92a19ae4a // indirect
google.golang.org/genproto v0.0.0-20190226184841-fc2db5cae922 // indirect
google.golang.org/grpc v1.19.0 // indirect
gopkg.in/resty.v1 v1.9.1
gopkg.in/square/go-jose.v2 v2.1.9
gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0
honnef.co/go/tools v0.0.0-20190215041234-466a0476246c // indirect
sourcegraph.com/sqs/pbtypes v1.0.0 // indirect
)
Loading

0 comments on commit 0fc875a

Please sign in to comment.