Exemple #1
0
func TestSign(t *testing.T) {
	assert := wcg.NewAssert(t)
	cmd := "sign foo"
	stdout := ExecToolEx(cmd)
	assert.EqStr(wcg.Sign("foo", "wcgsess")+"\n", stdout, cmd)

	cmd = "sign -k bar foo"
	stdout = ExecToolEx(cmd)
	assert.EqStr(wcg.Sign("foo", "bar")+"\n", stdout, cmd)
}
Exemple #2
0
func TestUnsign(t *testing.T) {
	assert := wcg.NewAssert(t)
	signedVal := wcg.Sign("foo", "wcgsess")
	cmd := "unsign " + signedVal
	stdout := ExecToolEx(cmd)
	assert.EqStr("foo\n", stdout, cmd)

	signedVal = wcg.Sign("foo", "bar")
	cmd = "unsign -k bar " + signedVal
	stdout = ExecToolEx(cmd)
	assert.EqStr("foo\n", stdout, cmd)

	// unsing error
	cmd = "unsign -k bar foo"
	ret, _, stderr := ExecTool(cmd)
	if ret != 1 {
		t.Errorf("unsing command should exit with 1 if the invalid value is passed.")
	}
	if !strings.HasPrefix(stderr, "Could not unsign the value") {
		t.Errorf("unsing command should report %q in stderr, but not\n"+
			"actual stderr was: %q", stderr)
	}
}
Exemple #3
0
package tools

import (
	"fmt"
	"github.com/codegangsta/cli"
	"github.com/speedland/wcg"
)

var CmdSign = cli.Command{
	Name:      "sign",
	ShortName: "s",
	Usage:     "Sign a value",
	Flags: []cli.Flag{
		cli.StringFlag{"key, k", "wcgsess", "secret key", "KEY"},
	},
	Action: func(c *cli.Context) {
		if len(c.Args()) != 1 {
			cli.ShowCommandHelp(c, "sign")
		} else {
			val := c.Args().First()
			key := c.String("key")
			fmt.Printf("%s\n", wcg.Sign(val, key))
		}
	},
}