Exemplo n.º 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)
		})

	})
}
Exemplo n.º 2
0
// NewMongoManager 创建基于mongodb存储的管理实例
func NewMongoManager(mongoCfg *token.MongoConfig) *Manager {
	m := NewManager()
	m.MapClientModel(models.NewClient())
	m.MapTokenModel(models.NewToken())
	m.MapAuthorizeGenerate(generates.NewAuthorizeGenerate())
	m.MapAccessGenerate(generates.NewAccessGenerate())
	m.MustTokenStorage(token.NewMongoStore(mongoCfg))

	return m
}