Ejemplo n.º 1
0
func (s *S) TestExamples(c *C) {
	for _, steps := range tests {
		if len(steps) < 2 || len(steps[0]) < 3 || !strings.HasPrefix(steps[0], "U: ") {
			c.Fatalf("Invalid test: %#v", steps)
		}
		auth := strings.Fields(steps[0][3:])
		client := scram.NewClient(sha1.New, auth[0], auth[1])
		first, done := true, false
		c.Logf("-----")
		c.Logf("%s", steps[0])
		for _, step := range steps[1:] {
			c.Logf("%s", step)
			switch step[:3] {
			case "N: ":
				client.SetNonce([]byte(step[3:]))
			case "C: ":
				if first {
					first = false
					done = client.Step(nil)
				}
				c.Assert(done, Equals, false)
				c.Assert(client.Err(), IsNil)
				c.Assert(string(client.Out()), Equals, step[3:])
			case "S: ":
				first = false
				done = client.Step([]byte(step[3:]))
			default:
				panic("invalid test line: " + step)
			}
		}
		c.Assert(done, Equals, true)
		c.Assert(client.Err(), IsNil)
	}
}
Ejemplo n.º 2
0
func saslNewScram(cred Credential) *saslScram {
	credsum := md5.New()
	credsum.Write([]byte(cred.Username + ":mongo:" + cred.Password))
	client := scram.NewClient(sha1.New, cred.Username, hex.EncodeToString(credsum.Sum(nil)))
	return &saslScram{cred: cred, client: client}
}