Exemplo n.º 1
0
func (s *KNFSuite) TestParsing(c *check.C) {
	err := Global(s.ConfigPath)

	c.Assert(err, check.IsNil)

	_, err = Reload()

	c.Assert(err, check.IsNil)
}
Exemplo n.º 2
0
func (s *KNFSuite) TestComments(c *check.C) {
	var err error

	err = Global(s.ConfigPath)

	c.Assert(global, check.NotNil)
	c.Assert(err, check.IsNil)

	c.Assert(GetI("comment:test1"), check.Equals, 100)
	c.Assert(GetI("comment:test2"), check.Not(check.Equals), 100)
	c.Assert(HasProp("comment:test2"), check.Equals, false)
}
Exemplo n.º 3
0
func (s *KNFSuite) SetUpSuite(c *check.C) {
	tmpdir := c.MkDir()

	s.ConfigPath = tmpdir + "/" + _CONFIG_FILE_NAME
	s.EmptyConfigPath = tmpdir + "/" + _CONFIG_EMPTY_FILE_NAME
	s.MalformedConfigPath = tmpdir + "/" + _CONFIG_MALFORMED_FILE_NAME

	err := ioutil.WriteFile(s.ConfigPath, []byte(_CONFIG_DATA), 0644)

	if err != nil {
		c.Fatal(err.Error())
	}

	err = ioutil.WriteFile(s.EmptyConfigPath, []byte(""), 0644)

	if err != nil {
		c.Fatal(err.Error())
	}

	err = ioutil.WriteFile(s.MalformedConfigPath, []byte(_CONFIG_MALF_DATA), 0644)

	if err != nil {
		c.Fatal(err.Error())
	}
}
Exemplo n.º 4
0
func (s *KNFSuite) TestFileMode(c *check.C) {
	var err error

	err = Global(s.ConfigPath)

	c.Assert(global, check.NotNil)
	c.Assert(err, check.IsNil)

	c.Assert(GetM("file-mode:test1"), check.Equals, os.FileMode(0644))
	c.Assert(GetM("file-mode:test2"), check.Equals, os.FileMode(0644))
	c.Assert(GetM("file-mode:test3"), check.Equals, os.FileMode(0))
	c.Assert(GetM("file-mode:test4"), check.Equals, os.FileMode(0))
	c.Assert(GetM("file-mode:test5"), check.Equals, os.FileMode(0))
}
Exemplo n.º 5
0
func (s *SSLLabsSuite) TestInfo(c *check.C) {
	api, err := NewAPI("SSLScanTester", "4.0.0")

	c.Assert(api, check.NotNil)
	c.Assert(err, check.IsNil)

	c.Assert(api.Info.EngineVersion, check.Equals, "1.24.4")
	c.Assert(api.Info.CriteriaVersion, check.Equals, "2009l")
}
Exemplo n.º 6
0
func (s *KNFSuite) TestFormating(c *check.C) {
	var err error

	err = Global(s.ConfigPath)

	c.Assert(global, check.NotNil)
	c.Assert(err, check.IsNil)

	c.Assert(GetI("formating:test1"), check.Equals, 1)
	c.Assert(GetI("formating:test2"), check.Equals, 2)
	c.Assert(GetI("formating:test3"), check.Equals, 3)
}
Exemplo n.º 7
0
func (s *KNFSuite) TestProps(c *check.C) {
	var err error

	err = Global(s.ConfigPath)

	c.Assert(global, check.NotNil)
	c.Assert(err, check.IsNil)

	props := Props("file-mode")

	c.Assert(props, check.HasLen, 5)
	c.Assert(
		props,
		check.DeepEquals,
		[]string{"test1", "test2", "test3", "test4", "test5"},
	)
}
Exemplo n.º 8
0
func (s *KNFSuite) TestSections(c *check.C) {
	var err error

	err = Global(s.ConfigPath)

	c.Assert(global, check.NotNil)
	c.Assert(err, check.IsNil)

	sections := Sections()

	c.Assert(sections, check.HasLen, 8)
	c.Assert(
		sections,
		check.DeepEquals,
		[]string{"formating", "string", "boolean", "integer", "file-mode", "comment", "macro", "k"},
	)
}
Exemplo n.º 9
0
func (s *KNFSuite) TestNil(c *check.C) {
	var nilConf *Config

	c.Assert(nilConf.GetS("formating:test1"), check.Equals, "")
	c.Assert(nilConf.GetI("formating:test1"), check.Equals, 0)
	c.Assert(nilConf.GetF("formating:test1"), check.Equals, 0.0)
	c.Assert(nilConf.GetB("formating:test1"), check.Equals, false)
	c.Assert(nilConf.GetM("formating:test1"), check.Equals, os.FileMode(0))
	c.Assert(nilConf.HasSection("formating"), check.Equals, false)
	c.Assert(nilConf.HasProp("formating:test1"), check.Equals, false)
	c.Assert(nilConf.Sections(), check.HasLen, 0)
	c.Assert(nilConf.Props("formating"), check.HasLen, 0)

	_, err := nilConf.Reload()

	c.Assert(err, check.NotNil)
	c.Assert(err.Error(), check.Equals, "Config is nil")

	errs := nilConf.Validate([]*Validator{})

	c.Assert(errs, check.Not(check.HasLen), 0)
	c.Assert(errs[0].Error(), check.Equals, "Config is nil")
}
Exemplo n.º 10
0
func (s *KNFSuite) TestMacro(c *check.C) {
	var err error

	err = Global(s.ConfigPath)

	c.Assert(global, check.NotNil)
	c.Assert(err, check.IsNil)

	c.Assert(GetS("macro:test1"), check.Equals, "100")
	c.Assert(GetI("macro:test1"), check.Equals, 100)
	c.Assert(GetS("macro:test2"), check.Equals, "100.50")
	c.Assert(GetS("macro:test3"), check.Equals, "Value is 100.50")
	c.Assert(GetS("macro:test4"), check.Equals, "\"Value is 100.50\"")
	c.Assert(GetS("macro:test5"), check.Equals, "{ABC}")
	c.Assert(GetS("macro:test6"), check.Equals, "{}")
}
Exemplo n.º 11
0
func (s *FSSuite) TestProperPath(c *check.C) {
	tmpFile := c.MkDir() + "/test.txt"

	os.OpenFile(tmpFile, os.O_CREATE, 0644)

	paths := []string{"/etc/sudoers", "/etc/passwd", tmpFile}

	c.Assert(ProperPath("DR", paths), check.Equals, "")
	c.Assert(ProperPath("FR", paths), check.Equals, "/etc/passwd")
	c.Assert(ProperPath("FRW", paths), check.Equals, tmpFile)
	c.Assert(ProperPath("FRWS", paths), check.Equals, "")
	c.Assert(ProperPath("F", paths), check.Equals, "/etc/sudoers")

	os.Remove(tmpFile)
}
Exemplo n.º 12
0
func (s *FSSuite) TestWalker(c *check.C) {
	tmpDir := c.MkDir()

	os.Chdir(tmpDir)

	tmpDir, _ = os.Getwd()

	os.MkdirAll(tmpDir+"/dir1/dir2/dir3/dir4", 0755)
	os.Chdir(tmpDir)

	c.Assert(Current(), check.Equals, tmpDir)
	c.Assert(Pop(), check.Equals, tmpDir)

	dirStack = nil

	c.Assert(Push("dir1"), check.Equals, tmpDir+"/dir1")
	c.Assert(Push("dir9"), check.Equals, "")
	c.Assert(Push("dir2/dir3"), check.Equals, tmpDir+"/dir1/dir2/dir3")
	c.Assert(Push("dir4"), check.Equals, tmpDir+"/dir1/dir2/dir3/dir4")
	c.Assert(Push("dir9"), check.Equals, "")
	c.Assert(Pop(), check.Equals, tmpDir+"/dir1/dir2/dir3")
	c.Assert(Pop(), check.Equals, tmpDir+"/dir1")
	c.Assert(Pop(), check.Equals, tmpDir)
	c.Assert(Pop(), check.Equals, tmpDir)
}
Exemplo n.º 13
0
func (s *KNFSuite) TestInteger(c *check.C) {
	var err error

	err = Global(s.ConfigPath)

	c.Assert(global, check.NotNil)
	c.Assert(err, check.IsNil)

	c.Assert(GetI("integer:test1"), check.Equals, 1)
	c.Assert(GetI("integer:test2"), check.Equals, -5)
	c.Assert(GetI("integer:test3"), check.Equals, 10000000)
	c.Assert(GetI("integer:test4"), check.Equals, 0)
	c.Assert(GetI("integer:test5"), check.Equals, 0xFF)
	c.Assert(GetF("integer:test6"), check.Equals, 123.4)
	c.Assert(GetF("integer:test7"), check.Equals, 123.456789)
	c.Assert(GetF("integer:test8"), check.Equals, 0.0)
	c.Assert(GetI("integer:test8"), check.Equals, 0)
	c.Assert(GetF("integer:test9"), check.Equals, 0.0)
}
Exemplo n.º 14
0
func (s *KNFSuite) TestBoolean(c *check.C) {
	var err error

	err = Global(s.ConfigPath)

	c.Assert(global, check.NotNil)
	c.Assert(err, check.IsNil)

	c.Assert(GetB("boolean:test1"), check.Equals, true)
	c.Assert(GetB("boolean:test2"), check.Equals, false)
	c.Assert(GetB("boolean:test3"), check.Equals, false)
	c.Assert(GetB("boolean:test4"), check.Equals, true)
	c.Assert(GetB("boolean:test5"), check.Equals, false)
	c.Assert(GetB("boolean:test6"), check.Equals, true)
}
Exemplo n.º 15
0
func (s *KNFSuite) TestStrings(c *check.C) {
	var err error

	err = Global(s.ConfigPath)

	c.Assert(global, check.NotNil)
	c.Assert(err, check.IsNil)

	c.Assert(GetS("string:test1"), check.Equals, "test")
	c.Assert(GetS("string:test2"), check.Equals, "true")
	c.Assert(GetS("string:test3"), check.Equals, "4500")
	c.Assert(GetS("string:test4"), check.Equals, "!$%^&")
	c.Assert(GetS("string:test5"), check.Equals, "long long long long text for test")
}
Exemplo n.º 16
0
func (s *FSSuite) TestList(c *check.C) {
	tmpDir := c.MkDir()

	os.Mkdir(tmpDir+"/.dir0", 0755)

	os.Create(tmpDir + "/.file0")
	os.Create(tmpDir + "/file1.mp3")
	os.Create(tmpDir + "/file2.jpg")

	os.Mkdir(tmpDir+"/dir1", 0755)
	os.Mkdir(tmpDir+"/dir2", 0755)

	os.Create(tmpDir + "/dir1/file3.mp3")
	os.Create(tmpDir + "/dir2/file4.wav")

	os.Mkdir(tmpDir+"/dir1/dir3", 0755)

	listing1 := List(tmpDir, false)
	listing2 := List(tmpDir, true)
	listing3 := ListAll(tmpDir, false)
	listing4 := ListAll(tmpDir, true)
	listing5 := ListAllDirs(tmpDir, false)
	listing6 := ListAllDirs(tmpDir, true)
	listing7 := ListAllFiles(tmpDir, false)
	listing8 := ListAllFiles(tmpDir, true)
	listing9 := ListAllFiles(tmpDir, true, &ListingFilter{MatchPatterns: []string{"*.mp3", "*.wav"}})
	listing10 := ListAllFiles(tmpDir, true, &ListingFilter{NotMatchPatterns: []string{"*.mp3"}})
	listing11 := List(tmpDir, true, &ListingFilter{Perms: "DR"})
	listing12 := List(tmpDir, true, &ListingFilter{NotPerms: "DR"})

	sort.Strings(listing1)
	sort.Strings(listing2)
	sort.Strings(listing3)
	sort.Strings(listing4)
	sort.Strings(listing5)
	sort.Strings(listing6)
	sort.Strings(listing7)
	sort.Strings(listing8)
	sort.Strings(listing9)
	sort.Strings(listing10)
	sort.Strings(listing11)
	sort.Strings(listing12)

	c.Assert(
		listing1,
		check.DeepEquals,
		[]string{".dir0", ".file0", "dir1", "dir2", "file1.mp3", "file2.jpg"},
	)

	c.Assert(
		listing2,
		check.DeepEquals,
		[]string{"dir1", "dir2", "file1.mp3", "file2.jpg"},
	)

	c.Assert(
		listing3,
		check.DeepEquals,
		[]string{".dir0", ".file0", "dir1", "dir1/dir3", "dir1/file3.mp3", "dir2", "dir2/file4.wav", "file1.mp3", "file2.jpg"},
	)

	c.Assert(
		listing4,
		check.DeepEquals,
		[]string{"dir1", "dir1/dir3", "dir1/file3.mp3", "dir2", "dir2/file4.wav", "file1.mp3", "file2.jpg"},
	)

	c.Assert(
		listing5,
		check.DeepEquals,
		[]string{".dir0", "dir1", "dir1/dir3", "dir2"},
	)

	c.Assert(
		listing6,
		check.DeepEquals,
		[]string{"dir1", "dir1/dir3", "dir2"},
	)

	c.Assert(
		listing7,
		check.DeepEquals,
		[]string{".file0", "dir1/file3.mp3", "dir2/file4.wav", "file1.mp3", "file2.jpg"},
	)

	c.Assert(
		listing8,
		check.DeepEquals,
		[]string{"dir1/file3.mp3", "dir2/file4.wav", "file1.mp3", "file2.jpg"},
	)

	c.Assert(
		listing9,
		check.DeepEquals,
		[]string{"dir1/file3.mp3", "dir2/file4.wav", "file1.mp3"},
	)

	c.Assert(
		listing10,
		check.DeepEquals,
		[]string{"dir2/file4.wav", "file2.jpg"},
	)

	c.Assert(
		listing11,
		check.DeepEquals,
		[]string{"dir1", "dir2"},
	)

	c.Assert(
		listing12,
		check.DeepEquals,
		[]string{"file1.mp3", "file2.jpg"},
	)
}
Exemplo n.º 17
0
func (s *SSLLabsSuite) TestAnalyze(c *check.C) {
	api, err := NewAPI("SSLScanTester", "4.0.0")

	c.Assert(api, check.NotNil)
	c.Assert(err, check.IsNil)

	progress, err := api.Analyze("https://api.ssllabs.com")

	c.Assert(progress, check.NotNil)
	c.Assert(err, check.IsNil)

	var info *AnalyzeInfo

	fmt.Printf("Progress: ")

	for {
		info, err = progress.Info()

		c.Assert(info, check.NotNil)
		c.Assert(err, check.IsNil)

		if info.Status == STATUS_ERROR {
			c.Fatal(info.StatusMessage)
		}

		if info.Status == STATUS_READY {
			break
		}

		fmt.Printf(".")

		time.Sleep(5 * time.Second)
	}

	fmt.Println(" DONE")

	c.Assert(info.Host, check.Equals, "https://api.ssllabs.com")
	c.Assert(info.Port, check.Equals, 443)
	c.Assert(info.Protocol, check.Equals, "HTTP")
	c.Assert(info.IsPublic, check.Equals, false)
	c.Assert(info.Status, check.Equals, "READY")
	c.Assert(info.Endpoints, check.Not(check.HasLen), 0)

	c.Assert(info.Endpoints[0].IPAdress, check.Equals, "64.41.200.100")
	c.Assert(info.Endpoints[0].ServerName, check.Equals, "www.ssllabs.com")
	c.Assert(info.Endpoints[0].Grade, check.Equals, "A")
	c.Assert(info.Endpoints[0].GradeTrustIgnored, check.Equals, "A")
	c.Assert(info.Endpoints[0].HasWarnings, check.Equals, false)
	c.Assert(info.Endpoints[0].IsExceptional, check.Equals, false)
	c.Assert(info.Endpoints[0].Progress, check.Equals, 100)
	c.Assert(info.Endpoints[0].Delegation, check.Equals, 1)
	c.Assert(info.Endpoints[0].Details, check.IsNil)

	detailedInfo, err := progress.DetailedInfo(info.Endpoints[0].IPAdress)

	c.Assert(err, check.IsNil)
	c.Assert(detailedInfo, check.NotNil)
	c.Assert(detailedInfo.Details, check.NotNil)

	details := detailedInfo.Details

	c.Assert(details.Key, check.NotNil)
	c.Assert(details.Key.Size, check.Equals, 2048)
	c.Assert(details.Key.Alg, check.Equals, "RSA")
	c.Assert(details.Key.DebianFlaw, check.Equals, false)
	c.Assert(details.Key.Strength, check.Equals, 2048)

	c.Assert(details.Cert, check.NotNil)
	c.Assert(details.Cert.Subject, check.Equals, "CN=ssllabs.com,O=Qualys, Inc.,L=Redwood City,ST=California,C=US")
	c.Assert(details.Cert.CommonNames, check.DeepEquals, []string{"ssllabs.com"})
	c.Assert(details.Cert.AltNames, check.DeepEquals, []string{"ssllabs.com", "*.ssllabs.com"})
	c.Assert(details.Cert.IssuerSubject, check.Equals, "CN=Entrust Certification Authority - L1K,OU=(c) 2012 Entrust, Inc. - for authorized use only,OU=See www.entrust.net/legal-terms,O=Entrust, Inc.,C=US")
	c.Assert(details.Cert.IssuerLabel, check.Equals, "Entrust Certification Authority - L1K")
	c.Assert(details.Cert.SigAlg, check.Equals, "SHA256withRSA")
	c.Assert(details.Cert.RevocationInfo, check.Equals, 3)
	c.Assert(details.Cert.CRLURIs, check.DeepEquals, []string{"http://crl.entrust.net/level1k.crl"})
	c.Assert(details.Cert.OCSPURIs, check.DeepEquals, []string{"http://ocsp.entrust.net"})
	c.Assert(details.Cert.RevocationStatus, check.Equals, REVOCATION_STATUS_NOT_REVOKED)
	c.Assert(details.Cert.CRLRevocationStatus, check.Equals, REVOCATION_STATUS_NOT_REVOKED)
	c.Assert(details.Cert.OCSPRevocationStatus, check.Equals, REVOCATION_STATUS_NOT_REVOKED)
	c.Assert(details.Cert.SGC, check.Equals, 0)
	c.Assert(details.Cert.ValidationType, check.Equals, "")
	c.Assert(details.Cert.Issues, check.Equals, 0)
	c.Assert(details.Cert.SCT, check.Equals, false)
	c.Assert(details.Cert.MustStaple, check.Equals, 0)
	c.Assert(details.Cert.SHA1Hash, check.Equals, "4c91b922af1d09702f9b6240da931b795445f70d")
	c.Assert(details.Cert.PINSHA256, check.Equals, "xkWf9Qfs1uZi2NcMV3Gdnrz1UF4FNAslzApMTwynaMU=")

	c.Assert(details.Chain, check.NotNil)
	c.Assert(details.Chain.Certs, check.Not(check.HasLen), 0)
	c.Assert(details.Chain.Issues, check.Equals, 0)

	c.Assert(details.Chain.Certs[0], check.NotNil)
	c.Assert(details.Chain.Certs[0].Subject, check.Equals, "CN=ssllabs.com,O=Qualys, Inc.,L=Redwood City,ST=California,C=US")
	c.Assert(details.Chain.Certs[0].Label, check.Equals, "ssllabs.com")
	c.Assert(details.Chain.Certs[0].NotBefore, check.Not(check.Equals), int64(0))
	c.Assert(details.Chain.Certs[0].NotAfter, check.Not(check.Equals), int64(0))
	c.Assert(details.Chain.Certs[0].IssuerSubject, check.Equals, "CN=Entrust Certification Authority - L1K,OU=(c) 2012 Entrust, Inc. - for authorized use only,OU=See www.entrust.net/legal-terms,O=Entrust, Inc.,C=US")
	c.Assert(details.Chain.Certs[0].IssuerLabel, check.Equals, "Entrust Certification Authority - L1K")
	c.Assert(details.Chain.Certs[0].SigAlg, check.Equals, "SHA256withRSA")
	c.Assert(details.Chain.Certs[0].Issues, check.Equals, 0)
	c.Assert(details.Chain.Certs[0].KeyAlg, check.Equals, "RSA")
	c.Assert(details.Chain.Certs[0].KeySize, check.Equals, 2048)
	c.Assert(details.Chain.Certs[0].KeyStrength, check.Equals, 2048)
	c.Assert(details.Chain.Certs[0].RevocationStatus, check.Equals, REVOCATION_STATUS_NOT_REVOKED)
	c.Assert(details.Chain.Certs[0].CRLRevocationStatus, check.Equals, REVOCATION_STATUS_NOT_REVOKED)
	c.Assert(details.Chain.Certs[0].OCSPRevocationStatus, check.Equals, REVOCATION_STATUS_NOT_REVOKED)
	c.Assert(details.Chain.Certs[0].Raw, check.Not(check.Equals), "")

	c.Assert(details.Chain.Certs[1], check.NotNil)
	c.Assert(details.Chain.Certs[1].Subject, check.Equals, "CN=Entrust Certification Authority - L1K,OU=(c) 2012 Entrust, Inc. - for authorized use only,OU=See www.entrust.net/legal-terms,O=Entrust, Inc.,C=US")
	c.Assert(details.Chain.Certs[1].Label, check.Equals, "Entrust Certification Authority - L1K")
	c.Assert(details.Chain.Certs[1].NotBefore, check.Not(check.Equals), int64(0))
	c.Assert(details.Chain.Certs[1].NotAfter, check.Not(check.Equals), int64(0))
	c.Assert(details.Chain.Certs[1].IssuerSubject, check.Equals, "CN=Entrust Root Certification Authority - G2,OU=(c) 2009 Entrust, Inc. - for authorized use only,OU=See www.entrust.net/legal-terms,O=Entrust, Inc.,C=US")
	c.Assert(details.Chain.Certs[1].IssuerLabel, check.Equals, "Entrust Root Certification Authority - G2")
	c.Assert(details.Chain.Certs[1].SigAlg, check.Equals, "SHA256withRSA")
	c.Assert(details.Chain.Certs[1].Issues, check.Equals, 0)
	c.Assert(details.Chain.Certs[1].KeyAlg, check.Equals, "RSA")
	c.Assert(details.Chain.Certs[1].KeySize, check.Equals, 2048)
	c.Assert(details.Chain.Certs[1].KeyStrength, check.Equals, 2048)
	c.Assert(details.Chain.Certs[1].RevocationStatus, check.Equals, REVOCATION_STATUS_NOT_REVOKED)
	c.Assert(details.Chain.Certs[1].CRLRevocationStatus, check.Equals, REVOCATION_STATUS_NOT_REVOKED)
	c.Assert(details.Chain.Certs[1].OCSPRevocationStatus, check.Equals, REVOCATION_STATUS_NOT_REVOKED)
	c.Assert(details.Chain.Certs[1].Raw, check.Not(check.Equals), "")

	c.Assert(details.Chain.Certs[2], check.NotNil)
	c.Assert(details.Chain.Certs[2].Subject, check.Equals, "CN=Entrust Root Certification Authority - G2,OU=(c) 2009 Entrust, Inc. - for authorized use only,OU=See www.entrust.net/legal-terms,O=Entrust, Inc.,C=US")
	c.Assert(details.Chain.Certs[2].Label, check.Equals, "Entrust Root Certification Authority - G2")
	c.Assert(details.Chain.Certs[2].NotBefore, check.Not(check.Equals), int64(0))
	c.Assert(details.Chain.Certs[2].NotAfter, check.Not(check.Equals), int64(0))
	c.Assert(details.Chain.Certs[2].IssuerSubject, check.Equals, "CN=Entrust Root Certification Authority,OU=(c) 2006 Entrust, Inc.,OU=www.entrust.net/CPS is incorporated by reference,O=Entrust, Inc.,C=US")
	c.Assert(details.Chain.Certs[2].IssuerLabel, check.Equals, "Entrust Root Certification Authority")
	c.Assert(details.Chain.Certs[2].SigAlg, check.Equals, "SHA256withRSA")
	c.Assert(details.Chain.Certs[2].Issues, check.Equals, 0)
	c.Assert(details.Chain.Certs[2].KeyAlg, check.Equals, "RSA")
	c.Assert(details.Chain.Certs[2].KeySize, check.Equals, 2048)
	c.Assert(details.Chain.Certs[2].KeyStrength, check.Equals, 2048)
	c.Assert(details.Chain.Certs[2].RevocationStatus, check.Equals, REVOCATION_STATUS_NOT_REVOKED)
	c.Assert(details.Chain.Certs[2].CRLRevocationStatus, check.Equals, REVOCATION_STATUS_NOT_REVOKED)
	c.Assert(details.Chain.Certs[2].OCSPRevocationStatus, check.Equals, REVOCATION_STATUS_NOT_REVOKED)
	c.Assert(details.Chain.Certs[2].Raw, check.Not(check.Equals), "")

	c.Assert(details.Protocols, check.Not(check.HasLen), 0)

	c.Assert(details.Protocols[0].ID, check.Equals, 769)
	c.Assert(details.Protocols[0].Name, check.Equals, "TLS")
	c.Assert(details.Protocols[0].Version, check.Equals, "1.0")
	c.Assert(details.Protocols[0].V2SuitesDisabled, check.Equals, false)
	c.Assert(details.Protocols[0].Q, check.IsNil)

	c.Assert(details.Protocols[1].ID, check.Equals, 770)
	c.Assert(details.Protocols[1].Name, check.Equals, "TLS")
	c.Assert(details.Protocols[1].Version, check.Equals, "1.1")
	c.Assert(details.Protocols[1].V2SuitesDisabled, check.Equals, false)
	c.Assert(details.Protocols[1].Q, check.IsNil)

	c.Assert(details.Protocols[2].ID, check.Equals, 771)
	c.Assert(details.Protocols[2].Name, check.Equals, "TLS")
	c.Assert(details.Protocols[2].Version, check.Equals, "1.2")
	c.Assert(details.Protocols[2].V2SuitesDisabled, check.Equals, false)
	c.Assert(details.Protocols[2].Q, check.IsNil)

	c.Assert(details.Suites, check.NotNil)
	c.Assert(details.Suites.List, check.Not(check.HasLen), 0)
	c.Assert(details.Suites.Preference, check.Equals, true)

	for _, suite := range details.Suites.List {
		switch suite.ID {
		case 22:
			c.Assert(suite.Name, check.Equals, "TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA")
			c.Assert(suite.CipherStrength, check.Equals, 112)
			c.Assert(suite.DHStrength, check.Equals, 2048)
			c.Assert(suite.DHP, check.Equals, 256)
			c.Assert(suite.DHG, check.Equals, 1)
			c.Assert(suite.DHYs, check.Equals, 256)
			c.Assert(suite.ECDHBits, check.Equals, 0)
			c.Assert(suite.ECDHStrength, check.Equals, 0)
			c.Assert(suite.Q, check.IsNil)

		case 49199:
			c.Assert(suite.Name, check.Equals, "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256")
			c.Assert(suite.CipherStrength, check.Equals, 128)
			c.Assert(suite.DHStrength, check.Equals, 0)
			c.Assert(suite.DHP, check.Equals, 0)
			c.Assert(suite.DHG, check.Equals, 0)
			c.Assert(suite.DHYs, check.Equals, 0)
			c.Assert(suite.ECDHBits, check.Equals, 256)
			c.Assert(suite.ECDHStrength, check.Equals, 3072)
			c.Assert(suite.Q, check.IsNil)
		}
	}

	c.Assert(details.ServerSignature, check.Equals, "Apache")
	c.Assert(details.PrefixDelegation, check.Equals, false)
	c.Assert(details.NonPrefixDelegation, check.Equals, true)
	c.Assert(details.VulnBeast, check.Equals, true)
	c.Assert(details.RenegSupport, check.Equals, 2)
	c.Assert(details.SessionResumption, check.Equals, 2)
	c.Assert(details.CompressionMethods, check.Equals, 0)
	c.Assert(details.SupportsNPN, check.Equals, false)
	c.Assert(details.NPNProtocols, check.Equals, "")
	c.Assert(details.SessionTickets, check.Equals, 0)
	c.Assert(details.OCSPStapling, check.Equals, false)
	c.Assert(details.StaplingRevocationStatus, check.Equals, 0)
	c.Assert(details.StaplingRevocationErrorMessage, check.Equals, "")
	c.Assert(details.SNIRequired, check.Equals, false)
	c.Assert(details.HTTPStatusCode, check.Equals, 302)
	c.Assert(details.HTTPForwarding, check.Equals, "https://www.ssllabs.com")
	c.Assert(details.SupportsRC4, check.Equals, false)
	c.Assert(details.RC4WithModern, check.Equals, false)
	c.Assert(details.RC4Only, check.Equals, false)
	c.Assert(details.ForwardSecrecy, check.Equals, 4)
	c.Assert(details.ProtocolIntolerance, check.Equals, 0)
	c.Assert(details.MiscIntolerance, check.Equals, 0)
	c.Assert(details.Heartbleed, check.Equals, false)
	c.Assert(details.Heartbeat, check.Equals, false)
	c.Assert(details.OpenSslCCS, check.Equals, 1)
	c.Assert(details.OpenSSLLuckyMinus20, check.Equals, 1)
	c.Assert(details.Poodle, check.Equals, false)
	c.Assert(details.PoodleTLS, check.Equals, 1)
	c.Assert(details.FallbackSCSV, check.Equals, true)
	c.Assert(details.Freak, check.Equals, false)
	c.Assert(details.HasSCT, check.Equals, 0)
	c.Assert(details.DHUsesKnownPrimes, check.Equals, 0)
	c.Assert(details.DHYsReuse, check.Equals, false)
	c.Assert(details.Logjam, check.Equals, false)
	c.Assert(details.DrownErrors, check.Equals, false)
	c.Assert(details.DrownVulnerable, check.Equals, false)

	c.Assert(details.SIMS, check.NotNil)
	c.Assert(details.SIMS.Results, check.Not(check.HasLen), 0)

	for _, suite := range details.SIMS.Results {
		c.Assert(suite.Client.ID, check.NotNil)

		switch suite.Client.ID {
		case 25:
			c.Assert(suite.Client, check.NotNil)
			c.Assert(suite.ProtocolID, check.Equals, 0)
			c.Assert(suite.Attempts, check.Equals, 1)
			c.Assert(suite.ErrorCode, check.Equals, 1)
			c.Assert(suite.SuiteID, check.Equals, 0)
			c.Assert(suite.Client.ID, check.Equals, 25)
			c.Assert(suite.Client.Name, check.Equals, "Java")
			c.Assert(suite.Client.Platform, check.Equals, "")
			c.Assert(suite.Client.Version, check.Equals, "6u45")
			c.Assert(suite.Client.IsReference, check.Equals, false)

		case 114:
			c.Assert(suite.Client, check.NotNil)
			c.Assert(suite.ProtocolID, check.Equals, 771)
			c.Assert(suite.Attempts, check.Equals, 1)
			c.Assert(suite.ErrorCode, check.Equals, 0)
			c.Assert(suite.SuiteID, check.Equals, 49199)
			c.Assert(suite.Client.Name, check.Equals, "Safari")
			c.Assert(suite.Client.Platform, check.Equals, "iOS 9")
			c.Assert(suite.Client.Version, check.Equals, "9")
			c.Assert(suite.Client.IsReference, check.Equals, true)
		}
	}

	c.Assert(details.HSTSPolicy.LongMaxAge, check.Equals, 15552000)
	c.Assert(details.HSTSPolicy.Header, check.Equals, "")
	c.Assert(details.HSTSPolicy.Status, check.Equals, HSTS_STATUS_ABSENT)
	c.Assert(details.HSTSPolicy.Error, check.Equals, "")
	c.Assert(details.HSTSPolicy.MaxAge, check.Equals, int64(0))
	c.Assert(details.HSTSPolicy.IncludeSubDomains, check.Equals, false)
	c.Assert(details.HSTSPolicy.Preload, check.Equals, false)

	c.Assert(details.HSTSPreloads, check.HasLen, 4)

	c.Assert(details.HSTSPreloads[0].Hostname, check.Equals, "api.ssllabs.com")
	c.Assert(details.HSTSPreloads[1].Hostname, check.Equals, "api.ssllabs.com")
	c.Assert(details.HSTSPreloads[2].Hostname, check.Equals, "api.ssllabs.com")
	c.Assert(details.HSTSPreloads[3].Hostname, check.Equals, "api.ssllabs.com")

	c.Assert(details.HSTSPreloads[0].Status, check.Equals, HSTS_STATUS_ABSENT)
	c.Assert(details.HSTSPreloads[1].Status, check.Equals, HSTS_STATUS_ABSENT)
	c.Assert(details.HSTSPreloads[2].Status, check.Equals, HSTS_STATUS_ABSENT)
	c.Assert(details.HSTSPreloads[3].Status, check.Equals, HSTS_STATUS_ABSENT)

	c.Assert(details.HSTSPreloads[0].Source, check.Equals, "Chrome")
	c.Assert(details.HSTSPreloads[1].Source, check.Equals, "Edge")
	c.Assert(details.HSTSPreloads[2].Source, check.Equals, "Firefox")
	c.Assert(details.HSTSPreloads[3].Source, check.Equals, "IE")

	c.Assert(details.HPKPPolicy, check.NotNil)
	c.Assert(details.HPKPPolicy.Header, check.Equals, "")
	c.Assert(details.HPKPPolicy.Status, check.Equals, HPKP_STATUS_ABSENT)
	c.Assert(details.HPKPPolicy.Pins, check.DeepEquals, []*Pin{})
	c.Assert(details.HPKPPolicy.MatchedPins, check.DeepEquals, []*Pin{})

	c.Assert(details.HPKPRoPolicy, check.NotNil)
	c.Assert(details.HPKPRoPolicy.Header, check.Equals, "")
	c.Assert(details.HPKPRoPolicy.Status, check.Equals, HPKP_STATUS_ABSENT)
	c.Assert(details.HPKPRoPolicy.Pins, check.DeepEquals, []*Pin{})
	c.Assert(details.HPKPRoPolicy.MatchedPins, check.DeepEquals, []*Pin{})

	c.Assert(details.DrownHosts, check.DeepEquals, []*DrownHost{})
}
Exemplo n.º 18
0
func (s *KNFSuite) TestDefault(c *check.C) {
	var err error

	err = Global(s.ConfigPath)

	c.Assert(global, check.NotNil)
	c.Assert(err, check.IsNil)

	c.Assert(GetS("string:test100", "fail"), check.Equals, "fail")
	c.Assert(GetB("boolean:test100", true), check.Equals, true)
	c.Assert(GetI("integer:test100", 9999), check.Equals, 9999)
	c.Assert(GetF("integer:test100", 123.45), check.Equals, 123.45)
	c.Assert(GetM("file-mode:test100", 0755), check.Equals, os.FileMode(0755))
	c.Assert(GetS("string:test6", "fail"), check.Equals, "fail")
}
Exemplo n.º 19
0
func (s *KNFSuite) TestErrors(c *check.C) {
	global = nil

	err := Global("/_not_exists_")

	c.Assert(err, check.NotNil)
	c.Assert(err.Error(), check.Equals, "File /_not_exists_ is not exist")

	err = Global(s.EmptyConfigPath)

	c.Assert(err, check.NotNil)
	c.Assert(err.Error(), check.Equals, fmt.Sprintf("File %s is empty", s.EmptyConfigPath))

	err = Global(s.MalformedConfigPath)

	c.Assert(err, check.NotNil)
	c.Assert(err.Error(), check.Equals, fmt.Sprintf("Configuration file %s is malformed", s.MalformedConfigPath))

	updated, err := Reload()

	c.Assert(updated, check.IsNil)
	c.Assert(err, check.NotNil)
	c.Assert(err.Error(), check.Equals, "Global config is not loaded")

	c.Assert(GetS("test"), check.Equals, "")
	c.Assert(GetI("test"), check.Equals, 0)
	c.Assert(GetF("test"), check.Equals, 0.0)
	c.Assert(GetB("test"), check.Equals, false)
	c.Assert(GetM("test"), check.Equals, os.FileMode(0))
	c.Assert(HasSection("test"), check.Equals, false)
	c.Assert(HasProp("test"), check.Equals, false)
	c.Assert(Sections(), check.HasLen, 0)
	c.Assert(Props("test"), check.HasLen, 0)
	c.Assert(Validate([]*Validator{}), check.Not(check.HasLen), 0)
	c.Assert(Validate([]*Validator{})[0].Error(), check.Equals, "Global config struct is nil")

	config := &Config{}

	c.Assert(config.GetS("test"), check.Equals, "")
	c.Assert(config.GetI("test"), check.Equals, 0)
	c.Assert(config.GetF("test"), check.Equals, 0.0)
	c.Assert(config.GetB("test"), check.Equals, false)
	c.Assert(config.GetM("test"), check.Equals, os.FileMode(0))
	c.Assert(config.HasSection("test"), check.Equals, false)
	c.Assert(config.HasProp("test"), check.Equals, false)
	c.Assert(config.Sections(), check.HasLen, 0)
	c.Assert(config.Props("test"), check.HasLen, 0)
	c.Assert(config.Validate([]*Validator{}), check.HasLen, 0)

	updated, err = config.Reload()

	c.Assert(updated, check.IsNil)
	c.Assert(err, check.NotNil)
	c.Assert(err.Error(), check.Equals, "Path to config file is empty (non initialized struct?)")

	config = &Config{file: "/_not_exists_"}

	updated, err = config.Reload()

	c.Assert(updated, check.IsNil)
	c.Assert(err, check.NotNil)
	c.Assert(err.Error(), check.Equals, "File /_not_exists_ is not exist")
}
Exemplo n.º 20
0
func (s *KNFSuite) TestValidation(c *check.C) {
	var err error

	err = Global(s.ConfigPath)

	c.Assert(global, check.NotNil)
	c.Assert(err, check.IsNil)

	var errs []error

	errs = Validate([]*Validator{
		{"integer:test1", Empty, nil},
		{"integer:test1", Less, 0},
		{"integer:test1", Less, 0.5},
		{"integer:test1", Greater, 10},
		{"integer:test1", Greater, 10.1},
		{"integer:test1", Equals, 10},
		{"integer:test1", Equals, 10.1},
		{"integer:test1", Equals, "123"},
	})

	c.Assert(errs, check.HasLen, 0)

	errs = Validate([]*Validator{
		{"boolean:test5", Empty, nil},
		{"integer:test1", Less, 10},
		{"integer:test1", Greater, 0},
		{"integer:test1", Equals, 1},
		{"integer:test1", Greater, "12345"},
		{"integer:test1", NotContains, []string{"A", "B", "C"}},
	})

	c.Assert(errs, check.HasLen, 6)

	c.Assert(errs[0].Error(), check.Equals, "Property boolean:test5 can't be empty")
	c.Assert(errs[1].Error(), check.Equals, "Property integer:test1 can't be less than 10")
	c.Assert(errs[2].Error(), check.Equals, "Property integer:test1 can't be greater than 0")
	c.Assert(errs[3].Error(), check.Equals, "Property integer:test1 can't be equal 1")
	c.Assert(errs[4].Error(), check.Equals, "Wrong validator for property integer:test1")
	c.Assert(errs[5].Error(), check.Equals, "Property integer:test1 doesn't contains any valid value")

	fakeConfig := &Config{
		data: map[string]string{
			"test:empty":   "",
			"test:string":  "test",
			"test:integer": "10",
			"test:float":   "10.0",
			"test:boolean": "false",
		},
	}

	c.Assert(Empty(fakeConfig, "test:empty", nil), check.NotNil)
	c.Assert(Empty(fakeConfig, "test:string", nil), check.IsNil)

	c.Assert(Less(fakeConfig, "test:integer", 30), check.NotNil)
	c.Assert(Less(fakeConfig, "test:integer", 5), check.IsNil)
	c.Assert(Less(fakeConfig, "test:float", 30.0), check.NotNil)
	c.Assert(Less(fakeConfig, "test:float", 5.0), check.IsNil)
	c.Assert(Less(fakeConfig, "test:string", "30"), check.NotNil)

	c.Assert(Greater(fakeConfig, "test:integer", 5), check.NotNil)
	c.Assert(Greater(fakeConfig, "test:integer", 30), check.IsNil)
	c.Assert(Greater(fakeConfig, "test:float", 5.0), check.NotNil)
	c.Assert(Greater(fakeConfig, "test:float", 30.0), check.IsNil)
	c.Assert(Greater(fakeConfig, "test:string", "30"), check.NotNil)

	c.Assert(Equals(fakeConfig, "test:empty", ""), check.NotNil)
	c.Assert(Equals(fakeConfig, "test:string", "test"), check.NotNil)
	c.Assert(Equals(fakeConfig, "test:integer", 10), check.NotNil)
	c.Assert(Equals(fakeConfig, "test:float", 10.0), check.NotNil)
	c.Assert(Equals(fakeConfig, "test:boolean", false), check.NotNil)

	c.Assert(Equals(fakeConfig, "test:empty", []string{}), check.NotNil)
	c.Assert(Equals(fakeConfig, "test:empty", "1"), check.IsNil)
	c.Assert(Equals(fakeConfig, "test:string", "testtest"), check.IsNil)
	c.Assert(Equals(fakeConfig, "test:integer", 15), check.IsNil)
	c.Assert(Equals(fakeConfig, "test:float", 130.0), check.IsNil)
	c.Assert(Equals(fakeConfig, "test:boolean", true), check.IsNil)

	c.Assert(NotContains(fakeConfig, "test:string", []string{"A", "B", "test"}), check.IsNil)
	c.Assert(NotContains(fakeConfig, "test:string", []string{"A", "B"}), check.NotNil)
	c.Assert(NotContains(fakeConfig, "test:string", 0), check.NotNil)
}
Exemplo n.º 21
0
func (s *KNFSuite) TestCheckers(c *check.C) {
	var err error

	err = Global(s.ConfigPath)

	c.Assert(global, check.NotNil)
	c.Assert(err, check.IsNil)

	c.Assert(HasSection("string"), check.Equals, true)
	c.Assert(HasSection("strings"), check.Equals, false)

	c.Assert(HasProp("string:test1"), check.Equals, true)
	c.Assert(HasProp("string:test6"), check.Equals, false)
	c.Assert(HasProp("strings:test6"), check.Equals, false)
}