Prefix replacement of the old application-nested module path in go.mod and every import. No identifier, string, table, migration ID, config key or comment changes.
57 lines
1.5 KiB
Go
57 lines
1.5 KiB
Go
package user
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"strings"
|
|
"testing"
|
|
|
|
"git.golem15.com/golem15/sm-user-plugin/models"
|
|
"git.golem15.com/golem15/summercms/modules/bonfire"
|
|
"git.golem15.com/golem15/summercms/modules/pact"
|
|
)
|
|
|
|
func TestRequirePasswordChange(t *testing.T) {
|
|
app, gdb := sessionApp(t, "0s")
|
|
user := insertUser(t, gdb, "alice@example.com", "correct-horse")
|
|
p := &Plugin{app: app}
|
|
var _ pact.HasCommands = p
|
|
cmds := p.Commands()
|
|
if len(cmds) != 1 || cmds[0].Name != "user:require-password-change" {
|
|
t.Fatalf("commands = %#v", cmds)
|
|
}
|
|
var buf bytes.Buffer
|
|
out := bonfire.NewOutput(nil, &buf, &buf)
|
|
if err := cmds[0].Run(context.Background(), emailArg{email: "alice@example.com"}, out); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !strings.Contains(buf.String(), "alice@example.com") {
|
|
t.Fatalf("output = %q", buf.String())
|
|
}
|
|
var fresh models.User
|
|
if err := gdb.First(&fresh, user.ID).Error; err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !fresh.MustChangePassword {
|
|
t.Fatal("must_change_password stayed false")
|
|
}
|
|
if err := cmds[0].Run(context.Background(), emailArg{email: "missing@example.com"}, out); err == nil {
|
|
t.Fatal("unknown email returned nil error")
|
|
}
|
|
}
|
|
|
|
type emailArg struct{ email string }
|
|
|
|
func (e emailArg) Args() []string { return []string{e.email} }
|
|
|
|
func (e emailArg) Argument(name string) (string, bool) {
|
|
if name == "email" {
|
|
return e.email, true
|
|
}
|
|
return "", false
|
|
}
|
|
|
|
func (e emailArg) Flag(string) (string, bool) { return "", false }
|
|
|
|
func (e emailArg) Flags(string) []string { return nil }
|