Skip to content

Commit

Permalink
BCDA-2995: Cleaned up minor code smells (#47)
Browse files Browse the repository at this point in the history
* BCDA-2995 removed duplicate test

* BCDA-2995 fixed function names to be in line go standards

* BCDA-2995 updated tests
  • Loading branch information
PatKelsh authored Jun 10, 2020
1 parent b728941 commit 70425e3
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
6 changes: 3 additions & 3 deletions ssas/rsakeys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type RSAKeysTestSuite struct {
suite.Suite
}

func (s *RSAKeysTestSuite) TestReadPrivateKey_EmptyKey() {
func (s *RSAKeysTestSuite) TestReadPrivateKeyEmptyKey() {
pemData, err := ReadPEMFile("")
assert.NotNil(s.T(), err)
assert.Contains(s.T(), err.Error(), "no such file or directory", "expected os.open error")
Expand All @@ -26,7 +26,7 @@ func (s *RSAKeysTestSuite) TestReadPrivateKey_EmptyKey() {
assert.Contains(s.T(), err.Error(), "empty or nil")
}

func (s *RSAKeysTestSuite) TestReadPrivateKey_BadKeys() {
func (s *RSAKeysTestSuite) TestReadPrivateKeyBadKeys() {
assertT := assert.New(s.T())
var tests = []struct {
path string
Expand All @@ -46,7 +46,7 @@ func (s *RSAKeysTestSuite) TestReadPrivateKey_BadKeys() {
}
}

func (s *RSAKeysTestSuite) TestReadPrivateKey_GoodKeys() {
func (s *RSAKeysTestSuite) TestReadPrivateKeyGoodKeys() {
// filePath := os.Getenv(goodTestKeyPath)
pemData, err := ReadPEMFile(goodTestKeyPath)
assert.Nil(s.T(), err)
Expand Down
11 changes: 6 additions & 5 deletions ssas/service/admin/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/CMSgov/bcda-ssas-app/ssas/service"
"io/ioutil"
"net/http"
"net/http/httptest"
"strconv"
"strings"
"testing"

"github.com/CMSgov/bcda-ssas-app/ssas/service"

"github.com/CMSgov/bcda-ssas-app/ssas"
"github.com/go-chi/chi"
"github.com/jinzhu/gorm"
Expand Down Expand Up @@ -359,15 +360,15 @@ func (s *APITestSuite) TestCreateSystemNoKey() {
assert.Nil(s.T(), err)
}

func (s *APITestSuite) TestCreateSystem_InvalidRequest() {
func (s *APITestSuite) TestCreateSystemInvalidRequest() {
req := httptest.NewRequest("POST", "/auth/system", strings.NewReader("{ badJSON }"))
handler := http.HandlerFunc(createSystem)
rr := httptest.NewRecorder()
handler.ServeHTTP(rr, req)
assert.Equal(s.T(), http.StatusBadRequest, rr.Result().StatusCode)
}

func (s *APITestSuite) TestCreateSystem_MissingRequiredParam() {
func (s *APITestSuite) TestCreateSystemMissingRequiredParam() {
req := httptest.NewRequest("POST", "/auth/system", strings.NewReader(`{"group_id": "T00001", "client_name": "Test Client 1", "scope": "bcda-api"}`))
handler := http.HandlerFunc(createSystem)
rr := httptest.NewRecorder()
Expand Down Expand Up @@ -403,7 +404,7 @@ func (s *APITestSuite) TestResetCredentials() {
_ = ssas.CleanDatabase(group)
}

func (s *APITestSuite) TestResetCredentials_InvalidSystemID() {
func (s *APITestSuite) TestResetCredentialsInvalidSystemID() {
systemID := "999"
req := httptest.NewRequest("PUT", "/system/"+systemID+"/credentials", nil)
rctx := chi.NewRouteContext()
Expand Down Expand Up @@ -478,7 +479,7 @@ func (s *APITestSuite) TestGetPublicKey() {
assert.Nil(s.T(), err)
}

func (s *APITestSuite) TestGetPublicKey_Rotation() {
func (s *APITestSuite) TestGetPublicKeyRotation() {
group := ssas.Group{GroupID: "api-test-get-public-key-group"}
err := s.db.Create(&group).Error
if err != nil {
Expand Down
11 changes: 6 additions & 5 deletions ssas/service/public/middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package public

import (
"context"
"github.com/CMSgov/bcda-ssas-app/ssas/service"
"github.com/go-chi/chi"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
"log"
"net/http"
"net/http/httptest"
"testing"

"github.com/CMSgov/bcda-ssas-app/ssas/service"
"github.com/go-chi/chi"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
)

var mockHandler http.HandlerFunc = func(w http.ResponseWriter, r *http.Request) {}
Expand Down Expand Up @@ -191,7 +192,7 @@ func (s *PublicMiddlewareTestSuite) TestRequireRegTokenAuthRevoked() {
}

func (s *PublicMiddlewareTestSuite) TestRequireRegTokenAuthEmptyToken() {
s.server = httptest.NewServer(s.CreateRouter(requireMFATokenAuth))
s.server = httptest.NewServer(s.CreateRouter(requireRegTokenAuth))
client := s.server.Client()

// Valid token should return a 200 response
Expand Down
7 changes: 4 additions & 3 deletions ssas/systems_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import (
"encoding/json"
"encoding/pem"
"fmt"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"net"
"os"
"strconv"
"strings"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/jinzhu/gorm"
"github.com/pborman/uuid"
"github.com/stretchr/testify/suite"
Expand Down Expand Up @@ -106,7 +107,7 @@ func (s *SystemsTestSuite) TestGenerateSystemKeyPair() {
assert.Nil(err)
}

func (s *SystemsTestSuite) TestGenerateSystemKeyPair_AlreadyExists() {
func (s *SystemsTestSuite) TestGenerateSystemKeyPairAlreadyExists() {
assert := s.Assert()

group := Group{GroupID: "bcdefa234561"}
Expand Down

0 comments on commit 70425e3

Please sign in to comment.