diff --git a/bindings/ndf.go b/bindings/ndf.go index 364a50502c97019d54a8eaf303f08b466f697c22..385fe25ea5db279ab5a89d6a7c36a173d3798ec7 100644 --- a/bindings/ndf.go +++ b/bindings/ndf.go @@ -18,33 +18,6 @@ import ( "net/http" ) -// ndfUrl is a hardcoded url to a bucket containing the signed NDF message. -const ndfUrl = `https://elixxir-bins.s3.us-west-1.amazonaws.com/ndf/default.json` - -// DownloadAndVerifySignedNdf retrieves the NDF from a hardcoded bucket URL. -// The NDF is processed into a protobuf containing a signature which -// is verified using the cert string passed in. The NDF is returned as marshaled -// byte data which may be used to start a client. -func DownloadAndVerifySignedNdf(cert string) ([]byte, error) { - // Build a request for the file - resp, err := http.Get(ndfUrl) - if err != nil { - return nil, errors.WithMessagef(err, "Failed to retrieve "+ - "NDF from %s", ndfUrl) - } - defer resp.Body.Close() - - // Download contents of the file - signedNdfEncoded, err := ioutil.ReadAll(resp.Body) - if err != nil { - return nil, errors.WithMessage(err, "Failed to read signed "+ - "NDF response request") - } - - // Process the download NDF and return the marshaled NDF - return processAndVerifySignedNdf(signedNdfEncoded, cert) -} - // DownloadAndVerifySignedNdfWithUrl retrieves the NDF from a specified URL. // The NDF is processed into a protobuf containing a signature which // is verified using the cert string passed in. The NDF is returned as marshaled diff --git a/bindings/ndf_test.go b/bindings/ndf_test.go index 73d5bbb9ec11ff592ae3751fab8367a6da21f218..d05bc5614e41a400e2a3df3bc819d4f091afb088 100644 --- a/bindings/ndf_test.go +++ b/bindings/ndf_test.go @@ -51,11 +51,11 @@ pipz4Cfpkoc1Gc8xx91iBsWYBpqu4p7SXDU= -----END CERTIFICATE----- ` -// Unit test: Download and verify NDF from hosted location. +// Unit Test: Call DownloadAndVerifySignedNdfWithUrl with a specified URL. // Ensure validity by unmarshalling NDF and checking the scheduling's cert. -func TestDownloadSignedNdf(t *testing.T) { - // Download and verify the ndf - content, err := DownloadAndVerifySignedNdf(testCert) +func TestDownloadSignedNdfWithUrl(t *testing.T) { + // Download and verify the cert with the specified URL + content, err := DownloadAndVerifySignedNdfWithUrl("https://elixxir-bins.s3.us-west-1.amazonaws.com/ndf/default.json", testCert) if err != nil { t.Errorf("Failed to download signed NDF: %v", err) } @@ -71,42 +71,21 @@ func TestDownloadSignedNdf(t *testing.T) { if strings.Compare(downloadedNdf.Registration.TlsCertificate, testCert) != 0 { t.Fatalf("Unexpected NDF downloaded, has the spec changed?") } - } // Error case: Pass in the incorrect cert forcing a verification failure. -func TestDownloadSignedNdf_Fail(t *testing.T) { +func TestDownloadSignedNdfWithUrl_BadCert(t *testing.T) { // Load an unintended cert badCert, err := utils.ReadFile(testkeys.GetGatewayCertPath()) if err != nil { t.Fatalf("Failed to read test certificate: %v", err) } - // Download and verify with unintended cert - _, err = DownloadAndVerifySignedNdf(string(badCert)) + + // Download and attempt to verify with unintended cert + _, err = DownloadAndVerifySignedNdfWithUrl("https://elixxir-bins.s3.us-west-1.amazonaws.com/ndf/default.json", + string(badCert)) if err == nil { t.Fatalf("Expected failure, should not be able to verify with " + "bad certificate") } } - -// Unit Test: Call DownloadAndVerifySignedNdfWithUrl with a specified URL. -// Ensure validity by unmarshalling NDF and checking the scheduling's cert. -func TestDownloadSignedNdfWithUrl(t *testing.T) { - // todo: write test once a proper URL can be passed in - content, err := DownloadAndVerifySignedNdfWithUrl(ndfUrl, testCert) - if err != nil { - t.Errorf("Failed to download signed NDF: %v", err) - } - fmt.Printf("content: %s\n", string(content)) - - // Check that it is a marshallable NDF - downloadedNdf, err := ndf.Unmarshal(content) - if err != nil { - t.Fatalf("Failed to unmarshal downloaded NDF: %v", err) - } - - // Check validity of NDF - if strings.Compare(downloadedNdf.Registration.TlsCertificate, testCert) != 0 { - t.Fatalf("Unexpected NDF downloaded, has the spec changed?") - } -}