Skip to content

Commit

Permalink
added urlcrlloader_test.go and bugfix related to file creation
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianRoettges committed Sep 27, 2023
1 parent 8df35de commit cae0444
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion crl/crlloader/filecrlloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (f FileLoader) copyToTargetFile(filePath string) error {
if stat.IsDir() {
return fmt.Errorf("CRL File %s is a directory", f.FileName)
}
crlFile, err := os.OpenFile(filePath, os.O_RDWR|os.O_EXCL|os.O_CREATE, 0600)
crlFile, err := os.OpenFile(filePath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion crl/crlloader/urlcrlloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (L URLLoader) GetDescription() string {
}

func (L URLLoader) downloadCRL(url string, filePath string) error {
crlFile, err := os.OpenFile(filePath, os.O_RDWR|os.O_EXCL|os.O_CREATE, 0600)
crlFile, err := os.OpenFile(filePath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
if err != nil {
return err
}
Expand Down
28 changes: 28 additions & 0 deletions crl/crlloader/urlcrlloader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,34 @@ func (suite *URLLoaderSuite) TestLoadCRL() {
assert.Equal(suite.T(), mockCRLContent, string(downloadedCRLData), "Downloaded CRL content doesn't match")
}

func (suite *URLLoaderSuite) TestLoadCRLWithInvalidUrl() {
// Create a temporary directory to store the downloaded CRL
tmpDir, err := ioutil.TempDir("", "test-crl-dir-")
assert.NoError(suite.T(), err, "Error creating temporary directory")
defer os.RemoveAll(tmpDir)

// Create a mock HTTP server that serves the CRL content
mockCRLContent := "Mock CRL Data"
mockServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(mockCRLContent))
}))
defer mockServer.Close()

// Create a URLLoader instance
urlLoader := URLLoader{
UrlString: "httppppp:dsdsd",
Logger: suite.logger,
}

// Define the path to save the downloaded CRL
downloadFilePath := filepath.Join(tmpDir, "downloaded-crl.crl")

// Call the LoadCRL method
err = urlLoader.LoadCRL(downloadFilePath)
assert.Error(suite.T(), err)
assert.Contains(suite.T(), err.Error(), "unsupported protocol")
}

func (suite *URLLoaderSuite) TestGetCRLLocationIdentifier() {
// Create a URLLoader instance
urlLoader := URLLoader{
Expand Down

0 comments on commit cae0444

Please sign in to comment.