Exemple #1
0
func TestManager(t *testing.T) {
	Convey("Manager test", t, func() {
		manager := NewManager()

		manager.MapClientModel(models.NewClient())
		manager.MapTokenModel(models.NewToken())
		manager.MapAuthorizeGenerate(generates.NewAuthorizeGenerate())
		manager.MapAccessGenerate(generates.NewAccessGenerate())
		manager.MapClientStorage(client.NewTempStore())

		Convey("GetClient test", func() {
			cli, err := manager.GetClient("1")
			So(err, ShouldBeNil)
			So(cli.GetSecret(), ShouldEqual, "11")
		})

		Convey("Redis store test", func() {
			manager.MustTokenStorage(token.NewRedisStore(
				&token.RedisConfig{Addr: "192.168.33.70:6379"},
			))
			testManager(manager)
		})

		Convey("MongoDB store test", func() {
			manager.MustTokenStorage(token.NewMongoStore(
				&token.MongoConfig{URL: "mongodb://*****:*****@192.168.33.70:27017"},
			))
			testManager(manager)
		})

	})
}
Exemple #2
0
// NewMongoManager 创建基于mysql存储的管理实例
func NewMysqlManager(mongoCfg *token.MysqlConfig) *Manager {
	m := NewManager()
	m.MapClientModel(models.NewClient())
	m.MapTokenModel(models.NewToken())
	m.MapAuthorizeGenerate(generates.NewAuthorizeGenerate())
	m.MapAccessGenerate(generates.NewAccessGenerate())
	m.MustTokenStorage(token.NewMysqlStore(mongoCfg))

	return m
}
Exemple #3
0
// NewRedisManager 创建基于redis存储的管理实例
func NewRedisManager(redisCfg *token.RedisConfig) *Manager {
	m := NewManager()
	m.MapClientModel(models.NewClient())
	m.MapTokenModel(models.NewToken())
	m.MapAuthorizeGenerate(generates.NewAuthorizeGenerate())
	m.MapAccessGenerate(generates.NewAccessGenerate())
	m.MustTokenStorage(token.NewRedisStore(redisCfg))

	return m
}