@@ -24,6 +24,7 @@ describe('Config', () => {
2424 const BLOCKED_TEMPLATE_HTML = readFileSync ( BLOCKED_TEMPLATE_HTML_PATH , { encoding : 'utf8' } )
2525 const BLOCKED_TEMPLATE_JSON_PATH = require . resolve ( './fixtures/config/appsec-blocked-template.json' )
2626 const BLOCKED_TEMPLATE_JSON = readFileSync ( BLOCKED_TEMPLATE_JSON_PATH , { encoding : 'utf8' } )
27+ const DD_GIT_PROPERTIES_FILE = require . resolve ( './fixtures/config/git.properties' )
2728
2829 beforeEach ( ( ) => {
2930 pkg = {
@@ -918,7 +919,7 @@ describe('Config', () => {
918919 }
919920 } )
920921
921- expect ( log . error ) . to . be . calledThrice
922+ expect ( log . error ) . to . be . callCount ( 4 )
922923 expect ( log . error . firstCall ) . to . have . been . calledWithExactly ( error )
923924 expect ( log . error . secondCall ) . to . have . been . calledWithExactly ( error )
924925 expect ( log . error . thirdCall ) . to . have . been . calledWithExactly ( error )
@@ -1058,4 +1059,73 @@ describe('Config', () => {
10581059 } )
10591060 } )
10601061 } )
1062+
1063+ context ( 'sci embedding' , ( ) => {
1064+ const DUMMY_COMMIT_SHA = 'b7b5dfa992008c77ab3f8a10eb8711e0092445b0'
1065+ const DUMMY_REPOSITORY_URL = '[email protected] :DataDog/dd-trace-js.git' 1066+ let ddTags
1067+ beforeEach ( ( ) => {
1068+ ddTags = process . env . DD_TAGS
1069+ } )
1070+ afterEach ( ( ) => {
1071+ delete process . env . DD_GIT_PROPERTIES_FILE
1072+ delete process . env . DD_GIT_COMMIT_SHA
1073+ delete process . env . DD_GIT_REPOSITORY_URL
1074+ delete process . env . DD_TRACE_GIT_METADATA_ENABLED
1075+ process . env . DD_TAGS = ddTags
1076+ } )
1077+ it ( 'reads DD_GIT_* env vars' , ( ) => {
1078+ process . env . DD_GIT_COMMIT_SHA = DUMMY_COMMIT_SHA
1079+ process . env . DD_GIT_REPOSITORY_URL = DUMMY_REPOSITORY_URL
1080+ const config = new Config ( { } )
1081+ expect ( config ) . to . have . property ( 'commitSHA' , DUMMY_COMMIT_SHA )
1082+ expect ( config ) . to . have . property ( 'repositoryUrl' , DUMMY_REPOSITORY_URL )
1083+ } )
1084+ it ( 'reads DD_TAGS env var' , ( ) => {
1085+ process . env . DD_TAGS = `git.commit.sha:${ DUMMY_COMMIT_SHA } ,git.repository_url:${ DUMMY_REPOSITORY_URL } `
1086+ process . env . DD_GIT_REPOSITORY_URL = DUMMY_REPOSITORY_URL
1087+ const config = new Config ( { } )
1088+ expect ( config ) . to . have . property ( 'commitSHA' , DUMMY_COMMIT_SHA )
1089+ expect ( config ) . to . have . property ( 'repositoryUrl' , DUMMY_REPOSITORY_URL )
1090+ } )
1091+ it ( 'reads git.properties if it is available' , ( ) => {
1092+ process . env . DD_GIT_PROPERTIES_FILE = DD_GIT_PROPERTIES_FILE
1093+ const config = new Config ( { } )
1094+ expect ( config ) . to . have . property ( 'commitSHA' , '4e7da8069bcf5ffc8023603b95653e2dc99d1c7d' )
1095+ expect ( config ) . to . have . property ( 'repositoryUrl' , DUMMY_REPOSITORY_URL )
1096+ } )
1097+ it ( 'does not crash if git.properties is not available' , ( ) => {
1098+ process . env . DD_GIT_PROPERTIES_FILE = '/does/not/exist'
1099+ const config = new Config ( { } )
1100+ expect ( config ) . to . have . property ( 'commitSHA' , undefined )
1101+ expect ( config ) . to . have . property ( 'repositoryUrl' , undefined )
1102+ } )
1103+ it ( 'does not read git.properties if env vars are passed' , ( ) => {
1104+ process . env . DD_GIT_PROPERTIES_FILE = DD_GIT_PROPERTIES_FILE
1105+ process . env . DD_GIT_COMMIT_SHA = DUMMY_COMMIT_SHA
1106+ process . env . DD_GIT_REPOSITORY_URL = 'https://github.com:env-var/dd-trace-js.git'
1107+ const config = new Config ( { } )
1108+ expect ( config ) . to . have . property ( 'commitSHA' , DUMMY_COMMIT_SHA )
1109+ expect ( config ) . to . have . property ( 'repositoryUrl' , 'https://github.com:env-var/dd-trace-js.git' )
1110+ } )
1111+ it ( 'still reads git.properties if one of the env vars is missing' , ( ) => {
1112+ process . env . DD_GIT_PROPERTIES_FILE = DD_GIT_PROPERTIES_FILE
1113+ process . env . DD_GIT_COMMIT_SHA = DUMMY_COMMIT_SHA
1114+ const config = new Config ( { } )
1115+ expect ( config ) . to . have . property ( 'commitSHA' , DUMMY_COMMIT_SHA )
1116+ expect ( config ) . to . have . property ( 'repositoryUrl' , DUMMY_REPOSITORY_URL )
1117+ } )
1118+ it ( 'reads git.properties and filters out credentials' , ( ) => {
1119+ process . env . DD_GIT_PROPERTIES_FILE = require . resolve ( './fixtures/config/git.properties.credentials' )
1120+ const config = new Config ( { } )
1121+ expect ( config ) . to . have . property ( 'commitSHA' , '4e7da8069bcf5ffc8023603b95653e2dc99d1c7d' )
1122+ expect ( config ) . to . have . property ( 'repositoryUrl' , 'https://github.com/datadog/dd-trace-js' )
1123+ } )
1124+ it ( 'does not read git metadata if DD_TRACE_GIT_METADATA_ENABLED is false' , ( ) => {
1125+ process . env . DD_TRACE_GIT_METADATA_ENABLED = 'false'
1126+ const config = new Config ( { } )
1127+ expect ( config ) . not . to . have . property ( 'commitSHA' )
1128+ expect ( config ) . not . to . have . property ( 'repositoryUrl' )
1129+ } )
1130+ } )
10611131} )
0 commit comments