github.com/web-platform-tests/wpt.fyi@v0.0.0-20240530210107-70cf978996f1/api/receiver/api_cloud_test.go (about)

     1  //go:build cloud
     2  // +build cloud
     3  
     4  // Copyright 2018 The WPT Dashboard Project. All rights reserved.
     5  // Use of this source code is governed by a BSD-style license that can be
     6  // found in the LICENSE file.
     7  
     8  package receiver
     9  
    10  import (
    11  	"bytes"
    12  	"context"
    13  	"net/http/httptest"
    14  	"testing"
    15  
    16  	"github.com/stretchr/testify/assert"
    17  	"github.com/stretchr/testify/require"
    18  	"github.com/web-platform-tests/wpt.fyi/shared"
    19  )
    20  
    21  // TestAuthenticateUploader relies on the setup of
    22  // TestCloudSecretManagerGetSecret in
    23  // shared/secret_manager_cloud_cloud_test.go
    24  func TestAuthenticateUploader(t *testing.T) {
    25  	ctx := context.Background()
    26  	err := shared.Clients.Init(ctx)
    27  	require.NoError(t, err)
    28  	a := NewAPI(ctx)
    29  
    30  	req := httptest.NewRequest("", "/api/foo", &bytes.Buffer{})
    31  	assert.Equal(t, "", AuthenticateUploader(a, req))
    32  
    33  	// Case 1: Try to get an uploader that does not exist
    34  	req.SetBasicAuth("bad-test-secret", "bad-value")
    35  	assert.Equal(t, "", AuthenticateUploader(a, req))
    36  
    37  	// Case 2: Try with correct username and password
    38  	req.SetBasicAuth("test-secret", "test-secret-value")
    39  	assert.Equal(t, "test-secret", AuthenticateUploader(a, req))
    40  
    41  	// Case 3: Try with correct username but bad password
    42  	req.SetBasicAuth("test-secret", "456")
    43  	assert.Equal(t, "", AuthenticateUploader(a, req))
    44  }