2022-09-28 09:01:17 +02:00
|
|
|
package entity
|
|
|
|
|
|
|
|
type SessionMap map[string]Session
|
|
|
|
|
|
|
|
func (m SessionMap) Get(name string) Session {
|
|
|
|
if result, ok := m[name]; ok {
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
|
|
|
return Session{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m SessionMap) Pointer(name string) *Session {
|
|
|
|
if result, ok := m[name]; ok {
|
|
|
|
return &result
|
|
|
|
}
|
|
|
|
|
|
|
|
return &Session{}
|
|
|
|
}
|
|
|
|
|
|
|
|
var SessionFixtures = SessionMap{
|
|
|
|
"alice": {
|
2022-10-03 22:59:29 +02:00
|
|
|
ID: "69be27ac5ca305b394046a83f6fda18167ca3d3f2dbe7ac0",
|
|
|
|
SessTimeout: UnixDay * 3,
|
|
|
|
SessExpires: UnixTime() + UnixWeek,
|
|
|
|
user: UserFixtures.Pointer("alice"),
|
|
|
|
UserUID: UserFixtures.Pointer("alice").UserUID,
|
|
|
|
UserName: UserFixtures.Pointer("alice").UserName,
|
2022-09-28 09:01:17 +02:00
|
|
|
},
|
|
|
|
"bob": {
|
2022-10-03 22:59:29 +02:00
|
|
|
ID: "69be27ac5ca305b394046a83f6fda18167ca3d3f2dbe7ac1",
|
|
|
|
SessTimeout: UnixDay * 3,
|
|
|
|
SessExpires: UnixTime() + UnixWeek,
|
|
|
|
user: UserFixtures.Pointer("bob"),
|
|
|
|
UserUID: UserFixtures.Pointer("bob").UserUID,
|
|
|
|
UserName: UserFixtures.Pointer("bob").UserName,
|
2022-09-28 09:01:17 +02:00
|
|
|
},
|
|
|
|
"unauthorized": {
|
2022-10-03 22:59:29 +02:00
|
|
|
ID: "69be27ac5ca305b394046a83f6fda18167ca3d3f2dbe7ac2",
|
|
|
|
SessTimeout: UnixDay * 3,
|
|
|
|
SessExpires: UnixTime() + UnixWeek,
|
|
|
|
user: UserFixtures.Pointer("unauthorized"),
|
|
|
|
UserUID: UserFixtures.Pointer("unauthorized").UserUID,
|
|
|
|
UserName: UserFixtures.Pointer("unauthorized").UserName,
|
2022-09-28 09:01:17 +02:00
|
|
|
},
|
|
|
|
"visitor": {
|
2022-10-03 22:59:29 +02:00
|
|
|
ID: "69be27ac5ca305b394046a83f6fda18167ca3d3f2dbe7ac3",
|
|
|
|
SessTimeout: UnixDay * 3,
|
|
|
|
SessExpires: UnixTime() + UnixWeek,
|
|
|
|
user: &Visitor,
|
|
|
|
UserUID: Visitor.UserUID,
|
|
|
|
UserName: Visitor.UserName,
|
|
|
|
DataJSON: []byte(`{"tokens":["1jxf3jfn2k"],"shares":["at9lxuqxpogaaba8"]}`),
|
2022-09-28 09:01:17 +02:00
|
|
|
data: &SessionData{
|
|
|
|
Tokens: []string{"1jxf3jfn2k"},
|
|
|
|
Shares: UIDs{"at9lxuqxpogaaba8"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"friend": {
|
2022-10-03 22:59:29 +02:00
|
|
|
ID: "69be27ac5ca305b394046a83f6fda18167ca3d3f2dbe7ac4",
|
|
|
|
SessTimeout: UnixDay * 3,
|
|
|
|
SessExpires: UnixTime() + UnixWeek,
|
|
|
|
user: UserFixtures.Pointer("friend"),
|
|
|
|
UserUID: UserFixtures.Pointer("friend").UserUID,
|
|
|
|
UserName: UserFixtures.Pointer("friend").UserName,
|
2022-09-28 09:01:17 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
// CreateSessionFixtures inserts known entities into the database for testing.
|
|
|
|
func CreateSessionFixtures() {
|
|
|
|
for _, entity := range SessionFixtures {
|
|
|
|
Db().Create(&entity)
|
|
|
|
}
|
|
|
|
}
|