summaryrefslogtreecommitdiff
path: root/backend_test.go
blob: 3452533e75da2f8c904b4ed32c26e43d12d8e32e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package secretsengine

import (
	"context"
	"fmt"

	log "github.com/hashicorp/go-hclog"
	"github.com/hashicorp/vault/sdk/helper/logging"
	"github.com/hashicorp/vault/sdk/logical"
)

func getBackend() (*krbBackend, logical.Storage) {
	config := &logical.BackendConfig{
		Logger:      logging.NewVaultLogger(log.Debug),
		StorageView: &logical.InmemStorage{},
	}

	b := newBackend()
	b.Setup(context.Background(), config)

	return b, config.StorageView
}

var _ KerberosClient = fakeLdapClient{}

type fakeLdapClient struct {
	passwords map[string]string
}

func (c fakeLdapClient) SetPassword(username string, password string) error {
	c.passwords[username] = password
	return nil
}

func (c fakeLdapClient) SetPasswordWithOld(username string, oldPassword, newPassword string) error {
	if realOldPassword, ok := c.passwords[username]; ok && oldPassword != realOldPassword {
		return fmt.Errorf("invalid old password")
	}
	c.passwords[username] = newPassword
	return nil
}