Skip to content

Commit

Permalink
🐛 add token
Browse files Browse the repository at this point in the history
Signed-off-by: Pranav Gaikwad <pgaikwad@redhat.com>
  • Loading branch information
pranavgaikwad committed Nov 15, 2023
1 parent e03665c commit c72eee7
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions analysis/analysis_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package analysis

import (
"crypto/aes"
"crypto/cipher"
"crypto/sha256"
"encoding/hex"
"os"
"sort"
"strings"
Expand Down Expand Up @@ -41,9 +45,15 @@ func TestApplicationAnalysis(t *testing.T) {
identity := &tc.Identities[idx]
uniq.IdentityName(identity)
if identity.Kind == "maven" {
identity.Settings = strings.Replace(identity.Settings, "GITHUB_USER", os.Getenv("MAVEN_TESTAPP_USER"), 1)
identity.Settings = strings.Replace(identity.Settings, "GITHUB_TOKEN", os.Getenv("MAVEN_TESTAPP_TOKEN"), 1)
t.Logf("using user %s", os.Getenv("MAVEN_TESTAPP_USER"))
mvnUser := os.Getenv("MAVEN_TESTAPP_USER")
mvnToken := os.Getenv("MAVEN_TESTAPP_TOKEN")
if mvnToken == "" && mvnUser == "" {
mvnUser = "konveyor-read-only-bot"
mvnToken = getDefaultToken()
}
identity.Settings = strings.Replace(identity.Settings, "GITHUB_USER", mvnUser, 1)
identity.Settings = strings.Replace(identity.Settings, "GITHUB_TOKEN", mvnToken, 1)
t.Logf("using mvn user %s", mvnUser)
}
assert.Should(t, RichClient.Identity.Create(identity))
tc.Application.Identities = append(tc.Application.Identities, api.Ref{ID: identity.ID})
Expand Down Expand Up @@ -264,3 +274,23 @@ func TestApplicationAnalysis(t *testing.T) {
})
}
}

func getDefaultToken() string {
key := sha256.Sum256([]byte("k0nv3y0r.io"))
enc, _ := hex.DecodeString("4b47536d696c993113c25974e461e2c8ae759dd9ef3c417d6be13e97f57b59b0c39ce49c1613641ec890e84dc7896e31f161747147e7ab3c024f3fbcb645cd8e57eacb6d")
block, err := aes.NewCipher(key[:])
if err != nil {
return ""
}
gcm, err := cipher.NewGCM(block)
if err != nil {
return ""
}
nonceSize := gcm.NonceSize()
nonce, ciphertext := enc[:nonceSize], enc[nonceSize:]
decrypted, err := gcm.Open(nil, nonce, ciphertext, nil)
if err != nil {
return ""
}
return string(decrypted)
}

0 comments on commit c72eee7

Please sign in to comment.