This repository has been archived by the owner on Dec 22, 2022. It is now read-only.
forked from prebid/prebid-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add SSL cert for accessing stored request API (prebid#1087)
- Loading branch information
1 parent
d90f492
commit ecfcf4f
Showing
6 changed files
with
104 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
-----BEGIN CERTIFICATE----- | ||
MIIBhTCCASugAwIBAgIQIRi6zePL6mKjOipn+dNuaTAKBggqhkjOPQQDAjASMRAw | ||
DgYDVQQKEwdBY21lIENvMB4XDTE3MTAyMDE5NDMwNloXDTE4MTAyMDE5NDMwNlow | ||
EjEQMA4GA1UEChMHQWNtZSBDbzBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABD0d | ||
7VNhbWvZLWPuj/RtHFjvtJBEwOkhbN/BnnE8rnZR8+sbwnc/KhCk3FhnpHZnQz7B | ||
5aETbbIgmuvewdjvSBSjYzBhMA4GA1UdDwEB/wQEAwICpDATBgNVHSUEDDAKBggr | ||
BgEFBQcDATAPBgNVHRMBAf8EBTADAQH/MCkGA1UdEQQiMCCCDmxvY2FsaG9zdDo1 | ||
NDUzgg4xMjcuMC4wLjE6NTQ1MzAKBggqhkjOPQQDAgNIADBFAiEA2zpJEPQyz6/l | ||
Wf86aX6PepsntZv2GYlA5UpabfT2EZICICpJ5h/iI+i341gBmLiAFQOyTDT+/wQc | ||
6MF9+Yw1Yy0t | ||
-----END CERTIFICATE----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package ssl | ||
|
||
import ( | ||
"crypto/x509" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestCertsFromFilePoolExists(t *testing.T) { | ||
// Load hardcoded certificates found in ssl.go | ||
certPool := GetRootCAPool() | ||
|
||
// Assert loaded certificates by looking at the length of the subjects array of strings | ||
subjects := certPool.Subjects() | ||
hardCodedSubNum := len(subjects) | ||
assert.True(t, hardCodedSubNum > 0) | ||
|
||
// Load certificates from file | ||
certificatesFile := "mockcertificates/mock-certs.pem" | ||
certPool, err := AppendPEMFileToRootCAPool(certPool, certificatesFile) | ||
|
||
// Assert loaded certificates by looking at the length of the subjects array of strings | ||
assert.NoError(t, err, "Error thrown by AppendPEMFileToRootCAPool while loading file %s: %v", certificatesFile, err) | ||
subjects = certPool.Subjects() | ||
subNumIncludingFile := len(subjects) | ||
assert.True(t, subNumIncludingFile > hardCodedSubNum, "subNumIncludingFile should be greater than hardCodedSubNum") | ||
} | ||
|
||
func TestCertsFromFilePoolDontExist(t *testing.T) { | ||
// Empty certpool | ||
var certPool *x509.CertPool = nil | ||
|
||
// Load certificates from file | ||
certificatesFile := "mockcertificates/mock-certs.pem" | ||
certPool, err := AppendPEMFileToRootCAPool(certPool, certificatesFile) | ||
|
||
// Assert loaded certificates by looking at the length of the subjects array of strings | ||
assert.NoError(t, err, "Error thrown by AppendPEMFileToRootCAPool while loading file %s: %v", certificatesFile, err) | ||
subjects := certPool.Subjects() | ||
assert.Equal(t, len(subjects), 1, "We only loaded one vertificate from the file, len(subjects) should equal 1") | ||
} | ||
|
||
func TestAppendPEMFileToRootCAPoolFail(t *testing.T) { | ||
// Empty certpool | ||
var certPool *x509.CertPool | ||
|
||
// In this test we are going to pass a file that does not exist as value of second argument | ||
fakeCertificatesFile := "mockcertificates/NO-FILE.pem" | ||
certPool, err := AppendPEMFileToRootCAPool(certPool, fakeCertificatesFile) | ||
|
||
// Assert AppendPEMFileToRootCAPool correctly throws an error when trying to load an nonexisting file | ||
assert.Errorf(t, err, "AppendPEMFileToRootCAPool should throw an error by while loading fake file %s \n", fakeCertificatesFile) | ||
} |