2018-01-18 00:48:32 +00:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hashicorp/vault/api"
|
|
|
|
vaulthttp "github.com/hashicorp/vault/http"
|
2019-04-12 21:54:35 +00:00
|
|
|
"github.com/hashicorp/vault/sdk/logical"
|
2018-01-18 00:48:32 +00:00
|
|
|
"github.com/hashicorp/vault/vault"
|
|
|
|
|
|
|
|
credAppId "github.com/hashicorp/vault/builtin/credential/app-id"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestPathMap_Upgrade_API(t *testing.T) {
|
|
|
|
var err error
|
|
|
|
coreConfig := &vault.CoreConfig{
|
|
|
|
DisableMlock: true,
|
|
|
|
DisableCache: true,
|
|
|
|
CredentialBackends: map[string]logical.Factory{
|
|
|
|
"app-id": credAppId.Factory,
|
|
|
|
},
|
2022-12-14 18:06:33 +00:00
|
|
|
PendingRemovalMountsAllowed: true,
|
2018-01-18 00:48:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cluster := vault.NewTestCluster(t, coreConfig, &vault.TestClusterOptions{
|
|
|
|
HandlerFunc: vaulthttp.Handler,
|
|
|
|
})
|
|
|
|
|
|
|
|
cluster.Start()
|
|
|
|
defer cluster.Cleanup()
|
|
|
|
|
|
|
|
cores := cluster.Cores
|
|
|
|
|
|
|
|
vault.TestWaitActive(t, cores[0].Core)
|
|
|
|
|
|
|
|
client := cores[0].Client
|
|
|
|
|
|
|
|
// Enable the app-id method
|
|
|
|
err = client.Sys().EnableAuthWithOptions("app-id", &api.EnableAuthOptions{
|
|
|
|
Type: "app-id",
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create an app-id
|
2022-04-07 19:12:58 +00:00
|
|
|
_, err = client.Logical().Write("auth/app-id/map/app-id/test-app-id", map[string]interface{}{
|
2018-01-18 00:48:32 +00:00
|
|
|
"policy": "test-policy",
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a user-id
|
2022-04-07 19:12:58 +00:00
|
|
|
_, err = client.Logical().Write("auth/app-id/map/user-id/test-user-id", map[string]interface{}{
|
2018-01-18 00:48:32 +00:00
|
|
|
"value": "test-app-id",
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Perform a login. It should succeed.
|
2022-04-07 19:12:58 +00:00
|
|
|
_, err = client.Logical().Write("auth/app-id/login", map[string]interface{}{
|
2018-01-18 00:48:32 +00:00
|
|
|
"app_id": "test-app-id",
|
|
|
|
"user_id": "test-user-id",
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// List the hashed app-ids in the storage
|
2022-04-07 19:12:58 +00:00
|
|
|
secret, err := client.Logical().List("auth/app-id/map/app-id")
|
2018-01-18 00:48:32 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
hashedAppID := secret.Data["keys"].([]interface{})[0].(string)
|
|
|
|
|
|
|
|
// Try reading it. This used to cause an issue which is fixed in [GH-3806].
|
2022-04-07 19:12:58 +00:00
|
|
|
_, err = client.Logical().Read("auth/app-id/map/app-id/" + hashedAppID)
|
2018-01-18 00:48:32 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure that there was no issue by performing another login
|
2022-04-07 19:12:58 +00:00
|
|
|
_, err = client.Logical().Write("auth/app-id/login", map[string]interface{}{
|
2018-01-18 00:48:32 +00:00
|
|
|
"app_id": "test-app-id",
|
|
|
|
"user_id": "test-user-id",
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|