コード例 #1
0
ファイル: service_test.go プロジェクト: joao-parana/csfw
// TestApplyCoreConfigData reads from the MySQL core_config_data table and applies
// these value to the underlying storage. tries to get back the values from the
// underlying storage
func TestApplyCoreConfigData(t *testing.T) {
	defer debugLogBuf.Reset()
	defer infoLogBuf.Reset()

	dbc := csdb.MustConnectTest()
	defer func() { assert.NoError(t, dbc.Close()) }()
	sess := dbc.NewSession(nil) // nil tricks the NewSession ;-)

	s := config.NewService()
	defer func() { assert.NoError(t, s.Close()) }()

	loadedRows, writtenRows, err := s.ApplyCoreConfigData(sess)
	if err != nil {
		t.Fatal(err)
	}
	assert.True(t, loadedRows > 9, "loadedRows %d", loadedRows)
	assert.True(t, writtenRows > 9, "writtenRows %d", writtenRows)

	//	println("\n", debugLogBuf.String(), "\n")
	//	println("\n", infoLogBuf.String(), "\n")

	assert.NoError(t, s.Write(config.Path("web/secure/offloader_header"), config.ScopeDefault(), config.Value("SSL_OFFLOADED")))

	h, err := s.String(config.Path("web/secure/offloader_header"), config.ScopeDefault())
	assert.NoError(t, err)
	assert.Exactly(t, "SSL_OFFLOADED", h)

	assert.Len(t, s.Storage.AllKeys(), writtenRows)
}
コード例 #2
0
ファイル: inspections.go プロジェクト: hafeez3000/csfw
// IsSecure checks if a request has been sent over a TLS connection. Also checks
// if the app runs behind a proxy server and therefore checks the off loader header.
func IsSecure(ctx context.Context, r *http.Request) bool {
	// due to import cycle this function must be in this package
	if r.TLS != nil {
		return true
	}

	oh := config.ContextMustReader(ctx).GetString(config.Path(PathOffloaderHeader), config.ScopeDefault())

	h := r.Header.Get(oh)
	hh := r.Header.Get("HTTP_" + oh)

	var isHttps bool
	switch "https" {
	case h, hh:
		isHttps = true
	}
	return isHttps
}
コード例 #3
0
ファイル: inspections.go プロジェクト: levcom/csfw
// IsSecure checks if a request has been sent over a TLS connection. Also checks
// if the app runs behind a proxy server and therefore checks the off loader header.
func IsSecure(cr config.Reader, r *http.Request) bool {
	// due to import cycle this function must be in this package
	if r.TLS != nil {
		return true
	}

	oh, err := cr.GetString(config.Path(PathOffloaderHeader), config.ScopeDefault())
	if err != nil {
		if PkgLog.IsDebug() {
			PkgLog.Debug("net.httputils.IsSecure.FromContextReader.GetString", "err", err, "path", PathOffloaderHeader)
		}
		return false
	}

	h := r.Header.Get(oh)
	hh := r.Header.Get("HTTP_" + oh)

	var isHTTPS bool
	switch "https" {
	case h, hh:
		isHTTPS = true
	}
	return isHTTPS
}