Example #1
0
func (t *CsrTest) Test_SetValidations_State() {
	csr := models.Csr{
		KeyBits:            2048,
		CsrAlgorithm:       "sha256",
		Country:            "JP",
		State:              "",
		Locality:           "Piyo",
		OrganizationalName: "fuga",
		OrganizationalUnit: "",
		CommonName:         "*.test.com",
	}
	v := &revel.Validation{}

	v.Clear()
	csr.State = ""
	csr.SetValidations(v)
	t.Assert(v.HasErrors() == true)

	v.Clear()
	csr.State = "Tokyo"
	csr.SetValidations(v)
	t.Assert(v.HasErrors() == false)

	v.Clear()
	csr.State = "tokyo"
	csr.SetValidations(v)
	t.Assert(v.HasErrors() == false)
}
Example #2
0
func (this *Csr) Create(csr *models.Csr) revel.Result {
	csr.SetValidations(this.Validation)
	if this.Validation.HasErrors() {
		this.Validation.Keep()
		this.FlashParams()

		this.Flash.Error("Create error")
		return this.Redirect(routes.Csr.New())
	}

	this.Dbm().Connection().Save(csr)

	this.Flash.Success("Create success")
	return this.Redirect(routes.Csr.Show(csr.ID))
}
Example #3
0
func (t *CsrTest) Test_SetValidations_OrganizationalUnit() {
	csr := models.Csr{
		KeyBits:            2048,
		CsrAlgorithm:       "sha256",
		Country:            "JP",
		State:              "tokyo",
		Locality:           "Meguro-ku",
		OrganizationalName: "fuga.,ltd.",
		OrganizationalUnit: "",
		CommonName:         "*.test.com",
	}
	v := &revel.Validation{}

	v.Clear()
	csr.OrganizationalUnit = ""
	csr.SetValidations(v)
	t.Assert(v.HasErrors() == false)

	csr.OrganizationalUnit = "fuga.,ltd."
	v.Clear()
	csr.SetValidations(v)
	t.Assert(v.HasErrors() == false)
}