summaryrefslogtreecommitdiffstats
path: root/sms-service
diff options
context:
space:
mode:
authorKiran Kamineni <kiran.k.kamineni@intel.com>2018-04-18 14:14:31 -0700
committerKiran Kamineni <kiran.k.kamineni@intel.com>2018-04-19 17:04:26 -0700
commit333da2a55ef9535a32d90e249ab7f3842944db6a (patch)
tree73b5947793668fbb3913e8eaec97a70707b1cc57 /sms-service
parentd2fb77cf298e97eeb998bf1a5e00f06431afd3fc (diff)
Adding unit tests for Vault backend
These unit tests create a mock vault server and run the commands through it to test the core functionality. Issue-ID: AAF-118 Change-Id: Iab658cc60590b98c1524ccd5d57986e1fe2594c9 Signed-off-by: Kiran Kamineni <kiran.k.kamineni@intel.com>
Diffstat (limited to 'sms-service')
-rw-r--r--sms-service/src/sms/Gopkg.lock482
-rw-r--r--sms-service/src/sms/auth/auth.go26
-rw-r--r--sms-service/src/sms/auth/auth_test.go44
-rw-r--r--sms-service/src/sms/backend/vault.go36
-rw-r--r--sms-service/src/sms/backend/vault_test.go211
-rw-r--r--sms-service/src/sms/handler/handler_test.go20
6 files changed, 783 insertions, 36 deletions
diff --git a/sms-service/src/sms/Gopkg.lock b/sms-service/src/sms/Gopkg.lock
new file mode 100644
index 0000000..c7684c7
--- /dev/null
+++ b/sms-service/src/sms/Gopkg.lock
@@ -0,0 +1,482 @@
+# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
+
+
+[[projects]]
+ name = "github.com/Jeffail/gabs"
+ packages = ["."]
+ revision = "2a3aa15961d5fee6047b8151b67ac2f08ba2c48c"
+ version = "1.0"
+
+[[projects]]
+ name = "github.com/SAP/go-hdb"
+ packages = [
+ "driver",
+ "driver/sqltrace",
+ "internal/bufio",
+ "internal/protocol",
+ "internal/unicode",
+ "internal/unicode/cesu8"
+ ]
+ revision = "18b52f9f36b84988ed1fa70daa79e4a7d9618f33"
+ version = "v0.11.0"
+
+[[projects]]
+ name = "github.com/SermoDigital/jose"
+ packages = [
+ ".",
+ "crypto",
+ "jws",
+ "jwt"
+ ]
+ revision = "f6df55f235c24f236d11dbcf665249a59ac2021f"
+ version = "1.1"
+
+[[projects]]
+ branch = "master"
+ name = "github.com/armon/go-metrics"
+ packages = ["."]
+ revision = "783273d703149aaeb9897cf58613d5af48861c25"
+
+[[projects]]
+ branch = "master"
+ name = "github.com/armon/go-radix"
+ packages = ["."]
+ revision = "1fca145dffbcaa8fe914309b1ec0cfc67500fe61"
+
+[[projects]]
+ branch = "master"
+ name = "github.com/denisenkom/go-mssqldb"
+ packages = [
+ ".",
+ "internal/cp"
+ ]
+ revision = "e32faac87a2220f9342289f2c3b567d1424b8ec5"
+
+[[projects]]
+ name = "github.com/elazarl/go-bindata-assetfs"
+ packages = ["."]
+ revision = "30f82fa23fd844bd5bb1e5f216db87fd77b5eb43"
+ version = "v1.0.0"
+
+[[projects]]
+ name = "github.com/fatih/structs"
+ packages = ["."]
+ revision = "a720dfa8df582c51dee1b36feabb906bde1588bd"
+ version = "v1.0"
+
+[[projects]]
+ name = "github.com/go-sql-driver/mysql"
+ packages = ["."]
+ revision = "a0583e0143b1624142adab07e0e97fe106d99561"
+ version = "v1.3"
+
+[[projects]]
+ branch = "master"
+ name = "github.com/gocql/gocql"
+ packages = [
+ ".",
+ "internal/lru",
+ "internal/murmur",
+ "internal/streams"
+ ]
+ revision = "3540fc649cd7fc57cef5612b7bacac7a4fc443d6"
+
+[[projects]]
+ name = "github.com/gogo/protobuf"
+ packages = ["proto"]
+ revision = "1adfc126b41513cc696b209667c8656ea7aac67c"
+ version = "v1.0.0"
+
+[[projects]]
+ name = "github.com/golang/protobuf"
+ packages = [
+ "proto",
+ "ptypes",
+ "ptypes/any",
+ "ptypes/duration",
+ "ptypes/timestamp"
+ ]
+ revision = "925541529c1fa6821df4e44ce2723319eb2be768"
+ version = "v1.0.0"
+
+[[projects]]
+ branch = "master"
+ name = "github.com/golang/snappy"
+ packages = ["."]
+ revision = "553a641470496b2327abcac10b36396bd98e45c9"
+
+[[projects]]
+ name = "github.com/gorilla/context"
+ packages = ["."]
+ revision = "1ea25387ff6f684839d82767c1733ff4d4d15d0a"
+ version = "v1.1"
+
+[[projects]]
+ name = "github.com/gorilla/mux"
+ packages = ["."]
+ revision = "53c1911da2b537f792e7cafcb446b05ffe33b996"
+ version = "v1.6.1"
+
+[[projects]]
+ branch = "master"
+ name = "github.com/hailocab/go-hostpool"
+ packages = ["."]
+ revision = "e80d13ce29ede4452c43dea11e79b9bc8a15b478"
+
+[[projects]]
+ branch = "master"
+ name = "github.com/hashicorp/errwrap"
+ packages = ["."]
+ revision = "7554cd9344cec97297fa6649b055a8c98c2a1e55"
+
+[[projects]]
+ branch = "master"
+ name = "github.com/hashicorp/go-cleanhttp"
+ packages = ["."]
+ revision = "d5fe4b57a186c716b0e00b8c301cbd9b4182694d"
+
+[[projects]]
+ branch = "master"
+ name = "github.com/hashicorp/go-hclog"
+ packages = ["."]
+ revision = "69ff559dc25f3b435631604f573a5fa1efdb6433"
+
+[[projects]]
+ branch = "master"
+ name = "github.com/hashicorp/go-immutable-radix"
+ packages = ["."]
+ revision = "7f3cd4390caab3250a57f30efdb2a65dd7649ecf"
+
+[[projects]]
+ branch = "master"
+ name = "github.com/hashicorp/go-memdb"
+ packages = ["."]
+ revision = "1289e7fffe71d8fd4d4d491ba9a412c50f244c44"
+
+[[projects]]
+ branch = "master"
+ name = "github.com/hashicorp/go-multierror"
+ packages = ["."]
+ revision = "b7773ae218740a7be65057fc60b366a49b538a44"
+
+[[projects]]
+ branch = "master"
+ name = "github.com/hashicorp/go-plugin"
+ packages = ["."]
+ revision = "e8d22c780116115ae5624720c9af0c97afe4f551"
+
+[[projects]]
+ branch = "master"
+ name = "github.com/hashicorp/go-rootcerts"
+ packages = ["."]
+ revision = "6bb64b370b90e7ef1fa532be9e591a81c3493e00"
+
+[[projects]]
+ branch = "master"
+ name = "github.com/hashicorp/go-uuid"
+ packages = ["."]
+ revision = "27454136f0364f2d44b1276c552d69105cf8c498"
+
+[[projects]]
+ branch = "master"
+ name = "github.com/hashicorp/go-version"
+ packages = ["."]
+ revision = "23480c0665776210b5fbbac6eaaee40e3e6a96b7"
+
+[[projects]]
+ branch = "master"
+ name = "github.com/hashicorp/golang-lru"
+ packages = [
+ ".",
+ "simplelru"
+ ]
+ revision = "0fb14efe8c47ae851c0034ed7a448854d3d34cf3"
+
+[[projects]]
+ branch = "master"
+ name = "github.com/hashicorp/hcl"
+ packages = [
+ ".",
+ "hcl/ast",
+ "hcl/parser",
+ "hcl/scanner",
+ "hcl/strconv",
+ "hcl/token",
+ "json/parser",
+ "json/scanner",
+ "json/token"
+ ]
+ revision = "ef8a98b0bbce4a65b5aa4c368430a80ddc533168"
+
+[[projects]]
+ name = "github.com/hashicorp/vault"
+ packages = [
+ "api",
+ "audit",
+ "builtin/credential/approle",
+ "builtin/logical/database/dbplugin",
+ "helper/builtinplugins",
+ "helper/certutil",
+ "helper/cidrutil",
+ "helper/compressutil",
+ "helper/consts",
+ "helper/errutil",
+ "helper/forwarding",
+ "helper/identity",
+ "helper/jsonutil",
+ "helper/locksutil",
+ "helper/logging",
+ "helper/mlock",
+ "helper/parseutil",
+ "helper/pgpkeys",
+ "helper/pluginutil",
+ "helper/policyutil",
+ "helper/reload",
+ "helper/salt",
+ "helper/storagepacker",
+ "helper/strutil",
+ "helper/tlsutil",
+ "helper/wrapping",
+ "helper/xor",
+ "http",
+ "logical",
+ "logical/framework",
+ "physical",
+ "physical/inmem",
+ "plugins",
+ "plugins/database/cassandra",
+ "plugins/database/hana",
+ "plugins/database/mongodb",
+ "plugins/database/mssql",
+ "plugins/database/mysql",
+ "plugins/database/postgresql",
+ "plugins/helper/database/connutil",
+ "plugins/helper/database/credsutil",
+ "plugins/helper/database/dbutil",
+ "shamir",
+ "vault",
+ "version"
+ ]
+ revision = "5dd7f25f5c4b541f2da62d70075b6f82771a650d"
+ version = "v0.10.0"
+
+[[projects]]
+ branch = "master"
+ name = "github.com/hashicorp/yamux"
+ packages = ["."]
+ revision = "2658be15c5f05e76244154714161f17e3e77de2e"
+
+[[projects]]
+ branch = "master"
+ name = "github.com/jefferai/jsonx"
+ packages = ["."]
+ revision = "9cc31c3135eef39b8e72585f37efa92b6ca314d0"
+
+[[projects]]
+ branch = "master"
+ name = "github.com/keybase/go-crypto"
+ packages = [
+ "brainpool",
+ "cast5",
+ "curve25519",
+ "ed25519",
+ "ed25519/internal/edwards25519",
+ "openpgp",
+ "openpgp/armor",
+ "openpgp/ecdh",
+ "openpgp/elgamal",
+ "openpgp/errors",
+ "openpgp/packet",
+ "openpgp/s2k",
+ "rsa"
+ ]
+ revision = "d11a37f123888ff060339f516e392032dfcb98ff"
+
+[[projects]]
+ branch = "master"
+ name = "github.com/lib/pq"
+ packages = [
+ ".",
+ "oid"
+ ]
+ revision = "d34b9ff171c21ad295489235aec8b6626023cd04"
+
+[[projects]]
+ branch = "master"
+ name = "github.com/mitchellh/copystructure"
+ packages = ["."]
+ revision = "d23ffcb85de31694d6ccaa23ccb4a03e55c1303f"
+
+[[projects]]
+ branch = "master"
+ name = "github.com/mitchellh/go-homedir"
+ packages = ["."]
+ revision = "b8bc1bf767474819792c23f32d8286a45736f1c6"
+
+[[projects]]
+ branch = "master"
+ name = "github.com/mitchellh/go-testing-interface"
+ packages = ["."]
+ revision = "a61a99592b77c9ba629d254a693acffaeb4b7e28"
+
+[[projects]]
+ branch = "master"
+ name = "github.com/mitchellh/mapstructure"
+ packages = ["."]
+ revision = "00c29f56e2386353d58c599509e8dc3801b0d716"
+
+[[projects]]
+ branch = "master"
+ name = "github.com/mitchellh/reflectwalk"
+ packages = ["."]
+ revision = "63d60e9d0dbc60cf9164e6510889b0db6683d98c"
+
+[[projects]]
+ name = "github.com/oklog/run"
+ packages = ["."]
+ revision = "4dadeb3030eda0273a12382bb2348ffc7c9d1a39"
+ version = "v1.0.0"
+
+[[projects]]
+ name = "github.com/patrickmn/go-cache"
+ packages = ["."]
+ revision = "a3647f8e31d79543b2d0f0ae2fe5c379d72cedc0"
+ version = "v2.1.0"
+
+[[projects]]
+ name = "github.com/ryanuber/go-glob"
+ packages = ["."]
+ revision = "572520ed46dbddaed19ea3d9541bdd0494163693"
+ version = "v0.1"
+
+[[projects]]
+ branch = "master"
+ name = "github.com/sethgrid/pester"
+ packages = ["."]
+ revision = "ed9870dad3170c0b25ab9b11830cc57c3a7798fb"
+
+[[projects]]
+ branch = "master"
+ name = "golang.org/x/crypto"
+ packages = [
+ "cast5",
+ "curve25519",
+ "ed25519",
+ "ed25519/internal/edwards25519",
+ "internal/chacha20",
+ "md4",
+ "openpgp",
+ "openpgp/armor",
+ "openpgp/elgamal",
+ "openpgp/errors",
+ "openpgp/packet",
+ "openpgp/s2k",
+ "poly1305",
+ "ssh"
+ ]
+ revision = "d6449816ce06963d9d136eee5a56fca5b0616e7e"
+
+[[projects]]
+ branch = "master"
+ name = "golang.org/x/net"
+ packages = [
+ "context",
+ "http/httpguts",
+ "http2",
+ "http2/hpack",
+ "idna",
+ "internal/timeseries",
+ "lex/httplex",
+ "trace"
+ ]
+ revision = "d41e8174641f662c5a2d1c7a5f9e828788eb8706"
+
+[[projects]]
+ branch = "master"
+ name = "golang.org/x/sys"
+ packages = ["unix"]
+ revision = "3ccc7e5779793fd54564baf60c51bf017955e0ba"
+
+[[projects]]
+ name = "golang.org/x/text"
+ packages = [
+ "collate",
+ "collate/build",
+ "internal/colltab",
+ "internal/gen",
+ "internal/tag",
+ "internal/triegen",
+ "internal/ucd",
+ "language",
+ "secure/bidirule",
+ "transform",
+ "unicode/bidi",
+ "unicode/cldr",
+ "unicode/norm",
+ "unicode/rangetable"
+ ]
+ revision = "f21a4dfb5e38f5895301dc265a8def02365cc3d0"
+ version = "v0.3.0"
+
+[[projects]]
+ branch = "master"
+ name = "google.golang.org/genproto"
+ packages = ["googleapis/rpc/status"]
+ revision = "7fd901a49ba6a7f87732eb344f6e3c5b19d1b200"
+
+[[projects]]
+ name = "google.golang.org/grpc"
+ packages = [
+ ".",
+ "balancer",
+ "balancer/base",
+ "balancer/roundrobin",
+ "codes",
+ "connectivity",
+ "credentials",
+ "encoding",
+ "encoding/proto",
+ "grpclb/grpc_lb_v1/messages",
+ "grpclog",
+ "health",
+ "health/grpc_health_v1",
+ "internal",
+ "keepalive",
+ "metadata",
+ "naming",
+ "peer",
+ "resolver",
+ "resolver/dns",
+ "resolver/passthrough",
+ "stats",
+ "status",
+ "tap",
+ "transport"
+ ]
+ revision = "d11072e7ca9811b1100b80ca0269ac831f06d024"
+ version = "v1.11.3"
+
+[[projects]]
+ name = "gopkg.in/inf.v0"
+ packages = ["."]
+ revision = "d2d2541c53f18d2a059457998ce2876cc8e67cbf"
+ version = "v0.9.1"
+
+[[projects]]
+ branch = "v2"
+ name = "gopkg.in/mgo.v2"
+ packages = [
+ ".",
+ "bson",
+ "internal/json",
+ "internal/sasl",
+ "internal/scram"
+ ]
+ revision = "3f83fa5005286a7fe593b055f0d7771a7dce4655"
+
+[solve-meta]
+ analyzer-name = "dep"
+ analyzer-version = 1
+ inputs-digest = "d19e17a023506ab731b0f26c6fcfebe581d4d5194af094aecea5e72daddd3ead"
+ solver-name = "gps-cdcl"
+ solver-version = 1
diff --git a/sms-service/src/sms/auth/auth.go b/sms-service/src/sms/auth/auth.go
index cfd693e..7172505 100644
--- a/sms-service/src/sms/auth/auth.go
+++ b/sms-service/src/sms/auth/auth.go
@@ -31,6 +31,15 @@ import (
var tlsConfig *tls.Config
+func checkError(err error, topic string) error {
+ if err != nil {
+ smslogger.WriteError(topic + ": " + err.Error())
+ return err
+ }
+
+ return nil
+}
+
// GetTLSConfig initializes a tlsConfig using the CA's certificate
// This config is then used to enable the server for mutual TLS
func GetTLSConfig(caCertFile string) (*tls.Config, error) {
@@ -105,36 +114,31 @@ func GeneratePGPKeyPair() (string, string, error) {
// public key
func EncryptPGPString(data string, pbKey string) (string, error) {
pbKeyBytes, err := base64.StdEncoding.DecodeString(pbKey)
- if err != nil {
- smslogger.WriteError("Error Decoding base64 public key: " + err.Error())
+ if checkError(err, "Decoding Base64 Public Key") != nil {
return "", err
}
dataBytes := []byte(data)
pbEntity, err := openpgp.ReadEntity(packet.NewReader(bytes.NewBuffer(pbKeyBytes)))
- if err != nil {
- smslogger.WriteError("Error reading entity from PGP key: " + err.Error())
+ if checkError(err, "Reading entity from PGP key") != nil {
return "", err
}
// encrypt string
buf := new(bytes.Buffer)
out, err := openpgp.Encrypt(buf, []*openpgp.Entity{pbEntity}, nil, nil, nil)
- if err != nil {
- smslogger.WriteError("Error Creating Encryption Pipe")
- smslogger.WriteError(err.Error())
+ if checkError(err, "Creating Encryption Pipe") != nil {
return "", err
}
+
_, err = out.Write(dataBytes)
- if err != nil {
- smslogger.WriteError("Error Writing to Encryption Pipe")
+ if checkError(err, "Writing to Encryption Pipe") != nil {
return "", err
}
err = out.Close()
- if err != nil {
- smslogger.WriteError("Error Closing Encryption Pipe")
+ if checkError(err, "Closing Encryption Pipe") != nil {
return "", err
}
diff --git a/sms-service/src/sms/auth/auth_test.go b/sms-service/src/sms/auth/auth_test.go
index 1cacfe6..cd11f85 100644
--- a/sms-service/src/sms/auth/auth_test.go
+++ b/sms-service/src/sms/auth/auth_test.go
@@ -40,3 +40,47 @@ func TestGetTLSConfig(t *testing.T) {
}
}
}
+
+func TestGeneratePGPKeyPair(t *testing.T) {
+
+ _, _, err := GeneratePGPKeyPair()
+ if err != nil {
+ t.Fatal("GeneratePGPKeyPair: Error generating keys")
+ }
+}
+
+func TestEncryptPGPString(t *testing.T) {
+
+ pbkey, _, err := GeneratePGPKeyPair()
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ _, err = EncryptPGPString("This is my data", pbkey)
+ if err != nil {
+ t.Fatal("EncryptPGPString: Error encrypting data")
+ }
+}
+
+func TestDecryptPGPString(t *testing.T) {
+
+ pbkey, prkey, err := GeneratePGPKeyPair()
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ str := "my test string"
+ encryptedStr, err := EncryptPGPString(str, pbkey)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ decryptedStr, err := DecryptPGPString(encryptedStr, prkey)
+ if err != nil {
+ t.Fatal("DecryptPGPString: Error Decrypting data")
+ }
+
+ if decryptedStr != str {
+ t.Fatal("DecryptPGPString: Decrypted string does not match original")
+ }
+}
diff --git a/sms-service/src/sms/backend/vault.go b/sms-service/src/sms/backend/vault.go
index 147d934..e26baff 100644
--- a/sms-service/src/sms/backend/vault.go
+++ b/sms-service/src/sms/backend/vault.go
@@ -47,10 +47,12 @@ type Vault struct {
prkey string
}
-// Init will initialize the vault connection
-// It will also create the initial policy if it does not exist
-// TODO: Check to see if we need to wait for vault to be running
-func (v *Vault) Init() error {
+// initVaultClient will create the initial
+// Vault strcuture and populate it with the
+// right values and it will also create
+// a vault client
+func (v *Vault) initVaultClient() error {
+
vaultCFG := vaultapi.DefaultConfig()
vaultCFG.Address = v.vaultAddress
client, err := vaultapi.NewClient(vaultCFG)
@@ -66,12 +68,22 @@ func (v *Vault) Init() error {
v.internalDomain = "smsinternaldomain"
v.internalDomainMounted = false
v.prkey = ""
+ return nil
+
+}
+
+// Init will initialize the vault connection
+// It will also initialize vault if it is not
+// already initialized.
+// The initial policy will also be created
+func (v *Vault) Init() error {
+ v.initVaultClient()
// Initialize vault if it is not already
// Returns immediately if it is initialized
v.initializeVault()
- err = v.initRole()
+ err := v.initRole()
if err != nil {
smslogger.WriteError(err.Error())
smslogger.WriteInfo("InitRole will try again later")
@@ -367,6 +379,10 @@ func (v *Vault) DeleteSecret(dom string, name string) error {
// and secret-id stored on disk
func (v *Vault) initRole() error {
+ if v.initRoleDone {
+ return nil
+ }
+
// Use the root token once here
v.vaultClient.SetToken(v.vaultToken)
defer v.vaultClient.ClearToken()
@@ -470,12 +486,10 @@ func (v *Vault) checkToken() error {
// Init Role if it is not yet done
// Role needs to be created before token can be created
- if v.initRoleDone == false {
- err := v.initRole()
- if err != nil {
- smslogger.WriteError(err.Error())
- return errors.New("Unable to initRole in checkToken")
- }
+ err := v.initRole()
+ if err != nil {
+ smslogger.WriteError(err.Error())
+ return errors.New("Unable to initRole in checkToken")
}
// Return immediately if token still has life
diff --git a/sms-service/src/sms/backend/vault_test.go b/sms-service/src/sms/backend/vault_test.go
index fbc0148..484c395 100644
--- a/sms-service/src/sms/backend/vault_test.go
+++ b/sms-service/src/sms/backend/vault_test.go
@@ -17,30 +17,215 @@
package backend
import (
-// "testing"
+ credAppRole "github.com/hashicorp/vault/builtin/credential/approle"
+ vaulthttp "github.com/hashicorp/vault/http"
+ vaultlogical "github.com/hashicorp/vault/logical"
+ vaulttesting "github.com/hashicorp/vault/vault"
+ "reflect"
+ smslog "sms/log"
+ "testing"
)
-var v *Vault
+var secret Secret
func init() {
- v = &Vault{}
+ smslog.Init("")
+ secret = Secret{
+ Name: "testsecret",
+ Values: map[string]interface{}{
+ "name": "john",
+ "age": "43",
+ "isadmin": "true",
+ },
+ }
}
-/*
-func TestInit(t *testing.T) {
- smsconfig.SMSConfig = &smsconfig.SMSConfiguration{BackendAddress: "http://localhost:8200"}
- v.Init()
- if v.vaultClient == nil {
+// Only needed when running tests against vault
+func createLocalVaultServer(t *testing.T) (*vaulttesting.TestCluster, *Vault) {
+ tc := vaulttesting.NewTestCluster(t,
+ &vaulttesting.CoreConfig{
+ DisableCache: true,
+ DisableMlock: true,
+ CredentialBackends: map[string]vaultlogical.Factory{
+ "approle": credAppRole.Factory,
+ },
+ },
+ &vaulttesting.TestClusterOptions{
+ HandlerFunc: vaulthttp.Handler,
+ NumCores: 1,
+ })
+
+ tc.Start()
+
+ v := &Vault{}
+ v.initVaultClient()
+ v.vaultToken = tc.RootToken
+ v.vaultClient = tc.Cores[0].Client
+
+ return tc, v
+}
+
+func TestInitVaultClient(t *testing.T) {
+
+ v := &Vault{}
+ v.vaultAddress = "https://localhost:8200"
+ err := v.initVaultClient()
+ if err != nil || v.vaultClient == nil {
t.Fatal("Init: Init() failed to create vaultClient")
}
}
+func TestInitRole(t *testing.T) {
+
+ tc, v := createLocalVaultServer(t)
+ defer tc.Cleanup()
+
+ v.vaultToken = tc.RootToken
+ v.vaultClient = tc.Cores[0].Client
+
+ err := v.initRole()
+
+ if err != nil {
+ t.Fatal("InitRole: InitRole() failed to create roles")
+ }
+}
func TestGetStatus(t *testing.T) {
- _, err := v.GetStatus()
- // Expect error as vault is not running
- if err == nil {
- t.Fatal("GetStatus: Error expected, none found")
+
+ tc, v := createLocalVaultServer(t)
+ defer tc.Cleanup()
+
+ st, err := v.GetStatus()
+
+ if err != nil {
+ t.Fatal("GetStatus: Returned error")
+ }
+
+ if st == true {
+ t.Fatal("GetStatus: Returned true. Expected false")
+ }
+}
+
+func TestCreateSecretDomain(t *testing.T) {
+
+ tc, v := createLocalVaultServer(t)
+ defer tc.Cleanup()
+
+ sd, err := v.CreateSecretDomain("testdomain")
+
+ if err != nil {
+ t.Fatal("CreateSecretDomain: Returned error")
+ }
+
+ if sd.Name != "testdomain" {
+ t.Fatal("CreateSecretDomain: Returned name does not match: " + sd.Name)
+ }
+
+ if sd.UUID == "" {
+ t.Fatal("CreateSecretDomain: Returned UUID is empty")
+ }
+}
+
+func TestDeleteSecretDomain(t *testing.T) {
+
+ tc, v := createLocalVaultServer(t)
+ defer tc.Cleanup()
+
+ _, err := v.CreateSecretDomain("testdomain")
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ err = v.DeleteSecretDomain("testdomain")
+ if err != nil {
+ t.Fatal("DeleteSecretDomain: Unable to delete domain")
+ }
+}
+
+func TestCreateSecret(t *testing.T) {
+
+ tc, v := createLocalVaultServer(t)
+ defer tc.Cleanup()
+
+ _, err := v.CreateSecretDomain("testdomain")
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ err = v.CreateSecret("testdomain", secret)
+
+ if err != nil {
+ t.Fatal("CreateSecret: Error Creating secret")
+ }
+}
+
+func TestGetSecret(t *testing.T) {
+
+ tc, v := createLocalVaultServer(t)
+ defer tc.Cleanup()
+
+ _, err := v.CreateSecretDomain("testdomain")
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ err = v.CreateSecret("testdomain", secret)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ sec, err := v.GetSecret("testdomain", secret.Name)
+ if err != nil {
+ t.Fatal("GetSecret: Error Creating secret")
+ }
+
+ if sec.Name != secret.Name {
+ t.Fatal("GetSecret: Returned incorrect name")
+ }
+
+ if reflect.DeepEqual(sec.Values, secret.Values) == false {
+ t.Fatal("GetSecret: Returned incorrect Values")
+ }
+}
+
+func TestListSecret(t *testing.T) {
+
+ tc, v := createLocalVaultServer(t)
+ defer tc.Cleanup()
+
+ _, err := v.CreateSecretDomain("testdomain")
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ err = v.CreateSecret("testdomain", secret)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ _, err = v.ListSecret("testdomain")
+ if err != nil {
+ t.Fatal("ListSecret: Returned error")
+ }
+}
+
+func TestDeleteSecret(t *testing.T) {
+
+ tc, v := createLocalVaultServer(t)
+ defer tc.Cleanup()
+
+ _, err := v.CreateSecretDomain("testdomain")
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ err = v.CreateSecret("testdomain", secret)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ err = v.DeleteSecret("testdomain", secret.Name)
+ if err != nil {
+ t.Fatal("DeleteSecret: Error Creating secret")
}
}
-*/
diff --git a/sms-service/src/sms/handler/handler_test.go b/sms-service/src/sms/handler/handler_test.go
index 6b43a28..52637f3 100644
--- a/sms-service/src/sms/handler/handler_test.go
+++ b/sms-service/src/sms/handler/handler_test.go
@@ -95,7 +95,7 @@ func TestCreateRouter(t *testing.T) {
}
func TestStatusHandler(t *testing.T) {
- req, err := http.NewRequest("GET", "/v1/sms/status", nil)
+ req, err := http.NewRequest("GET", "/v1/sms/quorum/status", nil)
if err != nil {
t.Fatal(err)
}
@@ -127,6 +127,24 @@ func TestStatusHandler(t *testing.T) {
}
}
+func TestUnsealHandler(t *testing.T) {
+ req, err := http.NewRequest("GET", "/v1/sms/quorum/unseal", nil)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ rr := httptest.NewRecorder()
+ hr := http.HandlerFunc(h.statusHandler)
+
+ hr.ServeHTTP(rr, req)
+
+ ret := rr.Code
+ if ret != http.StatusOK {
+ t.Errorf("statusHandler returned wrong status code: %v vs %v",
+ ret, http.StatusOK)
+ }
+}
+
func TestCreateSecretDomainHandler(t *testing.T) {
body := `{"uuid":"123e4567-e89b-12d3-a456-426655440000","name":"testdomain"}`
reader := strings.NewReader(body)