コード例 #1
0
ファイル: common.go プロジェクト: nanopack/portal
func SetCerts(certs []core.CertBundle) error {
	// in case of failure
	oldCerts, err := database.GetCerts()
	if err != nil {
		return err
	}

	// apply certs to proxymgr
	err = proxymgr.SetCerts(certs)
	if err != nil {
		return err
	}

	if !database.CentralStore {
		// save to backend
		err = database.SetCerts(certs)
		if err != nil {
			// undo proxymgr action
			if uerr := proxymgr.SetCerts(oldCerts); uerr != nil {
				err = fmt.Errorf("%v - %v", err.Error(), uerr.Error())
			}
			return err
		}
	}
	return nil
}
コード例 #2
0
ファイル: proxymgr_test.go プロジェクト: nanopack/portal
func TestSetCerts(t *testing.T) {
	if err := proxymgr.SetCerts([]core.CertBundle{testCert}); err != nil {
		t.Errorf("Failed to SET certs - %v", err)
		t.FailNow()
	}

	certs, err := proxymgr.GetCerts()
	if err != nil {
		t.Error(err)
	}

	if len(certs) == 1 && certs[0].Cert != testCert.Cert {
		t.Errorf("Read cert differs from written cert")
	}

	// test bad tls start (certs must be in place)
	config.RouteHttp = "0.0.0.0:9084"
	config.RouteTls = "!@#$%^&*"
	err = proxymgr.Init()
	if err == nil {
		fmt.Printf("Proxymgr init succeeded when it should have failed\n")
		os.Exit(1)
	}
}