Skip to content

Commit e2240e5

Browse files
committed
merge conflict
2 parents d8a260f + 6149fb5 commit e2240e5

File tree

2 files changed

+92
-0
lines changed

2 files changed

+92
-0
lines changed

options.go

+3
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ type Options struct {
6666

6767
// TLS Config to use. When set TLS will be negotiated.
6868
TLSConfig *tls.Config
69+
70+
//KeyNamespace used for prefixing/namespacing keys.
71+
KeyNamespace string
6972
}
7073

7174
func (o *Options) redisOptions() *redis.Options {

redis_test.go

+89
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,92 @@ func TestTokenStore(t *testing.T) {
103103
})
104104
})
105105
}
106+
107+
func TestTokenStoreWithKeyNamespace(t *testing.T) {
108+
Convey("Test redis token store", t, func() {
109+
cfg := &redis.Config{
110+
Addr: "127.0.0.1:6379",
111+
KeyNamespace: "test:",
112+
}
113+
store, err := redis.NewTokenStore(cfg)
114+
So(err, ShouldBeNil)
115+
116+
Convey("Test authorization code store", func() {
117+
info := &models.Token{
118+
ClientID: "1",
119+
UserID: "1_1",
120+
RedirectURI: "http://localhost/",
121+
Scope: "all",
122+
Code: "11_11_11",
123+
CodeCreateAt: time.Now(),
124+
CodeExpiresIn: time.Second * 5,
125+
}
126+
err := store.Create(info)
127+
So(err, ShouldBeNil)
128+
129+
cinfo, err := store.GetByCode(info.Code)
130+
So(err, ShouldBeNil)
131+
So(cinfo.GetUserID(), ShouldEqual, info.UserID)
132+
133+
err = store.RemoveByCode(info.Code)
134+
So(err, ShouldBeNil)
135+
136+
cinfo, err = store.GetByCode(info.Code)
137+
So(err, ShouldBeNil)
138+
So(cinfo, ShouldBeNil)
139+
})
140+
141+
Convey("Test access token store", func() {
142+
info := &models.Token{
143+
ClientID: "1",
144+
UserID: "1_1",
145+
RedirectURI: "http://localhost/",
146+
Scope: "all",
147+
Access: "1_1_1",
148+
AccessCreateAt: time.Now(),
149+
AccessExpiresIn: time.Second * 5,
150+
}
151+
err := store.Create(info)
152+
So(err, ShouldBeNil)
153+
154+
ainfo, err := store.GetByAccess(info.GetAccess())
155+
So(err, ShouldBeNil)
156+
So(ainfo.GetUserID(), ShouldEqual, info.GetUserID())
157+
158+
err = store.RemoveByAccess(info.GetAccess())
159+
So(err, ShouldBeNil)
160+
161+
ainfo, err = store.GetByAccess(info.GetAccess())
162+
So(err, ShouldBeNil)
163+
So(ainfo, ShouldBeNil)
164+
})
165+
166+
Convey("Test refresh token store", func() {
167+
info := &models.Token{
168+
ClientID: "1",
169+
UserID: "1_2",
170+
RedirectURI: "http://localhost/",
171+
Scope: "all",
172+
Access: "1_2_1",
173+
AccessCreateAt: time.Now(),
174+
AccessExpiresIn: time.Second * 5,
175+
Refresh: "1_2_2",
176+
RefreshCreateAt: time.Now(),
177+
RefreshExpiresIn: time.Second * 15,
178+
}
179+
err := store.Create(info)
180+
So(err, ShouldBeNil)
181+
182+
rinfo, err := store.GetByRefresh(info.GetRefresh())
183+
So(err, ShouldBeNil)
184+
So(rinfo.GetUserID(), ShouldEqual, info.GetUserID())
185+
186+
err = store.RemoveByRefresh(info.GetRefresh())
187+
So(err, ShouldBeNil)
188+
189+
rinfo, err = store.GetByRefresh(info.GetRefresh())
190+
So(err, ShouldBeNil)
191+
So(rinfo, ShouldBeNil)
192+
})
193+
})
194+
}

0 commit comments

Comments
 (0)