mirror of
				https://github.com/optim-enterprises-bv/vault.git
				synced 2025-10-30 18:17:55 +00:00 
			
		
		
		
	 993a1ae9f2
			
		
	
	993a1ae9f2
	
	
	
		
			
			* Implement config parameter to allow unathenticated metricss access * Add unit test for unauthenticated metrics access parameter * go mod tidy
		
			
				
	
	
		
			51 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			51 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package http
 | |
| 
 | |
| import (
 | |
| 	"testing"
 | |
| 	"time"
 | |
| 
 | |
| 	"github.com/armon/go-metrics"
 | |
| 	"github.com/hashicorp/vault/helper/metricsutil"
 | |
| 	"github.com/hashicorp/vault/vault"
 | |
| )
 | |
| 
 | |
| func TestSysMetricsUnauthenticated(t *testing.T) {
 | |
| 	inm := metrics.NewInmemSink(10*time.Second, time.Minute)
 | |
| 	metrics.DefaultInmemSignal(inm)
 | |
| 	conf := &vault.CoreConfig{
 | |
| 		BuiltinRegistry: vault.NewMockBuiltinRegistry(),
 | |
| 		MetricsHelper:   metricsutil.NewMetricsHelper(inm, false),
 | |
| 	}
 | |
| 	core, _, token := vault.TestCoreUnsealedWithConfig(t, conf)
 | |
| 	ln, addr := TestServer(t, core)
 | |
| 	TestServerAuth(t, addr, token)
 | |
| 
 | |
| 	// Default: Only authenticated access
 | |
| 	resp := testHttpGet(t, "", addr+"/v1/sys/metrics")
 | |
| 	testResponseStatus(t, resp, 400)
 | |
| 	resp = testHttpGet(t, token, addr+"/v1/sys/metrics")
 | |
| 	testResponseStatus(t, resp, 200)
 | |
| 
 | |
| 	// Close listener
 | |
| 	ln.Close()
 | |
| 
 | |
| 	// Setup new custom listener with unauthenticated metrics access
 | |
| 	ln, addr = TestListener(t)
 | |
| 	props := &vault.HandlerProperties{
 | |
| 		Core:                         core,
 | |
| 		MaxRequestSize:               DefaultMaxRequestSize,
 | |
| 		UnauthenticatedMetricsAccess: true,
 | |
| 	}
 | |
| 	TestServerWithListenerAndProperties(t, ln, addr, core, props)
 | |
| 	defer ln.Close()
 | |
| 	TestServerAuth(t, addr, token)
 | |
| 
 | |
| 	// Test without token
 | |
| 	resp = testHttpGet(t, "", addr+"/v1/sys/metrics")
 | |
| 	testResponseStatus(t, resp, 200)
 | |
| 
 | |
| 	// Should also work with token
 | |
| 	resp = testHttpGet(t, token, addr+"/v1/sys/metrics")
 | |
| 	testResponseStatus(t, resp, 200)
 | |
| }
 |