-
-
Notifications
You must be signed in to change notification settings - Fork 351
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Aeneas Rekkas (arekkas)
committed
Oct 14, 2016
1 parent
74b7f33
commit ae40691
Showing
7 changed files
with
226 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package integration_test | ||
|
||
//import ( | ||
// "testing" | ||
// | ||
// "github.com/ory-am/fosite/compose" | ||
// "github.com/ory-am/fosite/handler/oauth2" | ||
// "github.com/stretchr/testify/assert" | ||
// "github.com/stretchr/testify/require" | ||
// goauth "golang.org/x/oauth2" | ||
// "github.com/ory-am/fosite" | ||
//) | ||
// | ||
//func TestIntrospectToken(t *testing.T) { | ||
// for _, strategy := range []oauth2.AccessTokenStrategy{ | ||
// hmacStrategy, | ||
// } { | ||
// runIntrospectTokenTest(t, strategy) | ||
// } | ||
//} | ||
// | ||
//func runIntrospectTokenTest(t *testing.T, strategy oauth2.AccessTokenStrategy) { | ||
// f := compose.Compose(new(compose.Config), fositeStore, strategy, compose.OAuth2ClientCredentialsGrantFactory) | ||
// ts := mockServer(t, f, &mySessionData{ | ||
// HMACSession: new(oauth2.HMACSession), | ||
// }) | ||
// defer ts.Close() | ||
// | ||
// oauthClient := newOAuth2AppClient(ts) | ||
// resp := new(fosite.IntrospectionResponse) | ||
// for k, c := range []struct { | ||
// description string | ||
// setup func() | ||
// err bool | ||
// expect func() | ||
// }{ | ||
// { | ||
// description: "should pass", | ||
// setup: func() { | ||
// | ||
// }, | ||
// expect: func() { | ||
// | ||
// }, | ||
// }, | ||
// } { | ||
// c.setup() | ||
// | ||
// token, err := oauthClient.Token(goauth.NoContext) | ||
// require.Equal(t, c.err, err != nil, "(%d) %s\n%s\n%s", k, c.description, c.err, err) | ||
// if !c.err { | ||
// assert.NotEmpty(t, token.AccessToken, "(%d) %s\n%s", k, c.description, token) | ||
// } | ||
// t.Logf("Passed test case %d", k) | ||
// | ||
// | ||
// } | ||
//} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package fosite_test | ||
|
||
import ( | ||
"time" | ||
"testing" | ||
"github.com/ory-am/fosite" | ||
"github.com/stretchr/testify/assert" | ||
"net/http" | ||
"github.com/golang/mock/gomock" | ||
"github.com/ory-am/fosite/internal" | ||
"github.com/ory-am/fosite/compose" | ||
"net/url" | ||
|
||
. "github.com/ory-am/fosite" | ||
"github.com/ory-am/fosite/storage" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
func TestIntrospectionResponse(t *testing.T) { | ||
r := &fosite.IntrospectionResponse{ | ||
AccessRequester: fosite.NewAccessRequest(nil), | ||
ExpiresAt: time.Now(), | ||
Active: true, | ||
} | ||
|
||
assert.Equal(t, r.AccessRequester, r.GetAccessRequester()) | ||
assert.Equal(t, r.ExpiresAt, r.GetExpiresAt()) | ||
assert.Equal(t, r.Active, r.IsActive()) | ||
} | ||
|
||
func TestNewIntrospectionRequest(t *testing.T) { | ||
ctrl := gomock.NewController(t) | ||
validator := internal.NewMockTokenValidator(ctrl) | ||
defer ctrl.Finish() | ||
|
||
f := compose.ComposeAllEnabled(new(compose.Config), storage.NewMemoryStore(), []byte{}, nil).(*Fosite) | ||
httpreq := &http.Request{ | ||
Header: http.Header{}, | ||
Form: url.Values{}, | ||
} | ||
|
||
for k, c := range []struct { | ||
description string | ||
setup func() | ||
expectErr error | ||
isActive bool | ||
}{ | ||
{ | ||
description: "should fail", | ||
setup: func() { | ||
}, | ||
expectErr: ErrRequestUnauthorized, | ||
}, | ||
{ | ||
description: "should pass", | ||
setup: func() { | ||
f.TokenIntrospectionHandlers = TokenIntrospectionHandlers{validator} | ||
httpreq = &http.Request{ | ||
Header: http.Header{ | ||
"Authorization": []string{"bearer some-token"}, | ||
}, | ||
PostForm: url.Values{ | ||
"token": []string{"introspect-token"}, | ||
}, | ||
} | ||
validator.EXPECT().IntrospectToken(nil, "some-token", gomock.Any(), gomock.Any(), gomock.Any()).Return(nil) | ||
validator.EXPECT().IntrospectToken(nil, "introspect-token", gomock.Any(), gomock.Any(), gomock.Any()).Return(errors.New("")) | ||
}, | ||
isActive: false, | ||
}, | ||
{ | ||
description: "should pass", | ||
setup: func() { | ||
f.TokenIntrospectionHandlers = TokenIntrospectionHandlers{validator} | ||
httpreq = &http.Request{ | ||
Header: http.Header{ | ||
"Authorization": []string{"bearer some-token"}, | ||
}, | ||
PostForm: url.Values{ | ||
"token": []string{"introspect-token"}, | ||
}, | ||
} | ||
validator.EXPECT().IntrospectToken(nil, "some-token", gomock.Any(), gomock.Any(), gomock.Any()).Return(nil) | ||
validator.EXPECT().IntrospectToken(nil, "introspect-token", gomock.Any(), gomock.Any(), gomock.Any()).Return(nil) | ||
}, | ||
isActive: true, | ||
}, | ||
} { | ||
c.setup() | ||
res, err := f.NewIntrospectionRequest(nil, httpreq, nil) | ||
assert.True(t, errors.Cause(err) == c.expectErr, "(%d) %s\n%s\n%s", k, c.description, err, c.expectErr) | ||
if res != nil { | ||
assert.Equal(t, c.isActive, res.IsActive()) | ||
} | ||
t.Logf("Passed test case %d", k) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package fosite_test | ||
|
||
import ( | ||
"github.com/pkg/errors" | ||
"testing" | ||
. "github.com/ory-am/fosite" | ||
"github.com/ory-am/fosite/internal" | ||
"github.com/golang/mock/gomock" | ||
"net/http" | ||
) | ||
|
||
func TestWriteIntrospectionError(t *testing.T) { | ||
f := new(Fosite) | ||
c := gomock.NewController(t) | ||
defer c.Finish() | ||
|
||
rw := internal.NewMockResponseWriter(c) | ||
|
||
rw.EXPECT().WriteHeader(http.StatusUnauthorized)//[]byte("{\"active\":\"false\"}")) | ||
rw.EXPECT().Header().Return(http.Header{}) | ||
rw.EXPECT().Write(gomock.Any()) | ||
f.WriteIntrospectionError(rw, errors.Wrap(ErrRequestUnauthorized, "")) | ||
|
||
rw.EXPECT().Write([]byte("{\"active\":false}\n")) | ||
f.WriteIntrospectionError(rw, errors.New("")) | ||
|
||
f.WriteIntrospectionError(rw, nil) | ||
} | ||
|
||
func TestWriteIntrospectionResponse(t *testing.T) { | ||
f := new(Fosite) | ||
c := gomock.NewController(t) | ||
defer c.Finish() | ||
|
||
rw := internal.NewMockResponseWriter(c) | ||
rw.EXPECT().Write(gomock.Any()).AnyTimes() | ||
f.WriteIntrospectionResponse(rw, &IntrospectionResponse{ | ||
AccessRequester: NewAccessRequest(nil), | ||
}) | ||
} |