Skip to content

Commit

Permalink
Fix user ui refactoring issue (#759)
Browse files Browse the repository at this point in the history
* Certman refactor and automated reissuance (#753)

Co-authored-by: kbelita <[email protected]>
Co-authored-by: Daniel Sollis <[email protected]>

* sc-8837 Extend Background Color to bottom of Overview page (#754)

* sc-8408 Add min/max to date of incorporation field (#743)

* Handle multiple registered directories in BFF

* sc-8408 Add min/max to date of incorporation field

Co-authored-by: Benjamin Bengfort <[email protected]>

* sc-8837 Extend Background Color to bottom of Overview page

Co-authored-by: Benjamin Bengfort <[email protected]>
Co-authored-by: Cletus Razakou <[email protected]>

* fix conflict

Co-authored-by: Patrick Deziel <[email protected]>
Co-authored-by: kbelita <[email protected]>
Co-authored-by: Daniel Sollis <[email protected]>
Co-authored-by: elysee15 <[email protected]>
Co-authored-by: Benjamin Bengfort <[email protected]>
  • Loading branch information
6 people authored Sep 6, 2022
1 parent 6893fe8 commit b457fa8
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 31 deletions.
37 changes: 16 additions & 21 deletions pkg/gds/certman/certs.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,30 +253,25 @@ func (c *CertificateManager) submitCertificateRequest(r *models.CertificateReque
return fmt.Errorf("could not retrieve pkcs12password: %s", err)
}

// Allow multiple DNS names to be specified in addition to the common name
// This will overwrite whatever is in the params ensuring the latest common name and
// dns names are submitted to Sectigo if there were intermediate changes to the req.
dnsNames := []string{r.CommonName}
dnsNames = append(dnsNames, r.DnsNames...)
models.UpdateCertificateRequestParams(r, sectigo.ParamDNSNames, strings.Join(dnsNames, "\n"))
models.UpdateCertificateRequestParams(r, sectigo.ParamCommonName, r.CommonName)
models.UpdateCertificateRequestParams(r, sectigo.ParamPassword, string(pkcs12Password))

// Step 3: submit the certificate
var (
rep *sectigo.BatchResponse
params map[string]string
)

// Construct the required parameters for the Sectigo request.
profile := c.certs.Profile()
batchName := fmt.Sprintf("%s-certreq-%s)", c.conf.DirectoryID, r.Id)

if params, err = models.GetCertificateRequestParams(r, profile); err != nil {
return fmt.Errorf("could not retrieve certificate request parameters for profile %q: %s", profile, err)
var params map[string]string
if profile == sectigo.ProfileCipherTraceEndEntityCertificate || profile == sectigo.ProfileIDCipherTraceEndEntityCertificate {
params = r.Params
if params == nil {
log.Error().Str("vasp", vasp.Id).Str("certreq", r.Id).Msg("certificate request params are nil")
return errors.New("no params are available on the certificate request")
}
} else {
params = make(map[string]string)
}

// Execute the certificate request to Sectigo.
params["commonName"] = r.CommonName
params["dNSName"] = r.CommonName
params["pkcs12Password"] = string(pkcs12Password)

// Step 3: submit the certificate
var rep *sectigo.BatchResponse
batchName := fmt.Sprintf("%s-certreq-%s)", c.conf.DirectoryID, r.Id)
if rep, err = c.certs.CreateSingleCertBatch(authority, batchName, params); err != nil {
// Although the error may be logged again by the calling function, log the error
// here as well to provide debugging information about why the Sectigo request failed.
Expand Down
13 changes: 4 additions & 9 deletions pkg/gds/certman/certs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package certman_test

import (
"context"
"io/ioutil"
"net/http"
"os"
"path/filepath"
Expand Down Expand Up @@ -668,20 +669,14 @@ func (s *certTestSuite) TestSubmitBatchError() {
require.NoError(sm.CreateSecret(ctx, "password"))
require.NoError(sm.AddSecretVersion(ctx, "password", []byte("qDhAwnfMjgDEzzUC")))

// Create a valid certificate request with extended parameters
// Certificate request with a missing country name
quebecCertReq.Params = map[string]string{
"organizationName": "TRISA Member VASP",
"localityName": "Menlo Park",
"stateOrProvinceName": "California",
"country": "US",
}
require.NoError(s.db.UpdateCertReq(quebecCertReq))

// Ensure that Sectigo returns an error response when the batch is submitted.
mock.Handle(sectigo.CreateSingleCertBatchEP, func(c *gin.Context) {
c.JSON(http.StatusBadRequest, gin.H{"error": "bad request"})
})

// Run the CertManager for a tick
s.certman.HandleCertificateRequests()

Expand All @@ -693,7 +688,7 @@ func (s *certTestSuite) TestSubmitBatchError() {
// Cert request should still be in the READY_TO_SUBMIT state
cert, err := s.db.RetrieveCertReq(quebecCertReq.Id)
require.NoError(err)
require.Equal(models.CertificateRequestState_READY_TO_SUBMIT, cert.Status, "certificate request is not in ready to submit state")
require.Equal(models.CertificateRequestState_READY_TO_SUBMIT, cert.Status)

// Audit log should be updated
log, err := models.GetAuditLog(v)
Expand Down Expand Up @@ -934,7 +929,7 @@ func (s *certTestSuite) setupCertManager(profile string, fType fixtures.FixtureT

// Create the certificate manager configuration
var err error
certPath, err := os.MkdirTemp("testdata", "certs-*")
certPath, err := ioutil.TempDir("testdata", "certs-*")
require.NoError(err, "could not create cert storage")
s.conf.CertMan.Storage = certPath
s.conf.CertMan.RequestInterval = time.Millisecond
Expand Down
127 changes: 127 additions & 0 deletions pkg/gds/models/v1/models.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion web/gds-user-ui/src/modules/auth/login/user.slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,12 @@ export const getAuth0User: any = createAsyncThunk(
try {
// then login with auth0
const getUserInfo: any = hasToken && (await auth0Hash());
// console.log('[getUserInfo]', getUserInfo);
console.log('[getUserInfo]', getUserInfo);
setCookie('access_token', getUserInfo?.accessToken);
setCookie('user_locale', getUserInfo?.idTokenPayload?.locale || 'en');
if (getUserInfo && getUserInfo?.idTokenPayload?.email_verified) {
const getUser = await logUserInBff();
console.log('[getUser]', getUser);
// check if user response contains refresh_token flag
if (getUser?.data?.refresh_token) {
// refresh token
Expand Down

0 comments on commit b457fa8

Please sign in to comment.