@@ -1057,10 +1057,7 @@ public void CanPrettifyAMessage()
1057
1057
Assert . Equal ( expected , Commit . PrettifyMessage ( input . Replace ( '#' , ';' ) , ';' ) ) ;
1058
1058
}
1059
1059
1060
- [ Fact ]
1061
- public void CanExtractSignatureFromCommit ( )
1062
- {
1063
- string commitData = @"tree 6b79e22d69bf46e289df0345a14ca059dfc9bdf6
1060
+ private readonly string signedCommit = @"tree 6b79e22d69bf46e289df0345a14ca059dfc9bdf6
1064
1061
parent 34734e478d6cf50c27c9d69026d93974d052c454
1065
1062
author Ben Burkert <[email protected] > 1358451456 -0800
1066
1063
committer Ben Burkert <[email protected] > 1358451456 -0800
1085
1082
a simple commit which works
1086
1083
" ;
1087
1084
1088
- string signatureData = @"-----BEGIN PGP SIGNATURE-----
1085
+ private readonly string signatureData = @"-----BEGIN PGP SIGNATURE-----
1089
1086
Version: GnuPG v1.4.12 (Darwin)
1090
1087
1091
1088
iQIcBAABAgAGBQJQ+FMIAAoJEH+LfPdZDSs1e3EQAJMjhqjWF+WkGLHju7pTw2al
@@ -1103,19 +1100,23 @@ a simple commit which works
1103
1100
=ozeK
1104
1101
-----END PGP SIGNATURE-----" ;
1105
1102
1106
- string signedData = @"tree 6b79e22d69bf46e289df0345a14ca059dfc9bdf6
1103
+ private readonly string signedData = @"tree 6b79e22d69bf46e289df0345a14ca059dfc9bdf6
1107
1104
parent 34734e478d6cf50c27c9d69026d93974d052c454
1108
1105
author Ben Burkert <[email protected] > 1358451456 -0800
1109
1106
committer Ben Burkert <[email protected] > 1358451456 -0800
1110
1107
1111
1108
a simple commit which works
1112
1109
" ;
1113
1110
1111
+
1112
+ [ Fact ]
1113
+ public void CanExtractSignatureFromCommit ( )
1114
+ {
1114
1115
string repoPath = InitNewRepository ( ) ;
1115
1116
using ( var repo = new Repository ( repoPath ) )
1116
1117
{
1117
1118
var odb = repo . ObjectDatabase ;
1118
- var signedId = odb . Write < Commit > ( Encoding . UTF8 . GetBytes ( commitData ) ) ;
1119
+ var signedId = odb . Write < Commit > ( Encoding . UTF8 . GetBytes ( signedCommit ) ) ;
1119
1120
1120
1121
// Look up the commit to make sure we wrote something valid
1121
1122
var commit = repo . Lookup < Commit > ( signedId ) ;
@@ -1124,6 +1125,48 @@ a simple commit which works
1124
1125
var signatureInfo = Commit . ExtractSignature ( repo , signedId , "gpgsig" ) ;
1125
1126
Assert . Equal ( signedData , signatureInfo . SignedData ) ;
1126
1127
Assert . Equal ( signatureData , signatureInfo . Signature ) ;
1128
+
1129
+ signatureInfo = Commit . ExtractSignature ( repo , signedId ) ;
1130
+ Assert . Equal ( signedData , signatureInfo . SignedData ) ;
1131
+ Assert . Equal ( signatureData , signatureInfo . Signature ) ;
1132
+ }
1133
+ }
1134
+
1135
+ [ Fact ]
1136
+ public void CanCreateACommitString ( )
1137
+ {
1138
+ string repoPath = SandboxStandardTestRepo ( ) ;
1139
+ using ( var repo = new Repository ( repoPath ) )
1140
+ {
1141
+ var tipCommit = repo . Head . Tip ;
1142
+ var recreatedCommit = Commit . CreateBuffer (
1143
+ tipCommit . Author ,
1144
+ tipCommit . Committer ,
1145
+ tipCommit . Message ,
1146
+ tipCommit . Tree ,
1147
+ tipCommit . Parents ,
1148
+ false , null ) ;
1149
+
1150
+ var recreatedId = repo . ObjectDatabase . Write < Commit > ( Encoding . UTF8 . GetBytes ( recreatedCommit ) ) ;
1151
+ Assert . Equal ( tipCommit . Id , recreatedId ) ;
1152
+ }
1153
+ }
1154
+
1155
+ [ Fact ]
1156
+ public void CanCreateASignedCommit ( )
1157
+ {
1158
+ string repoPath = InitNewRepository ( ) ;
1159
+ using ( var repo = new Repository ( repoPath ) )
1160
+ {
1161
+ var odb = repo . ObjectDatabase ;
1162
+ var signedId = odb . Write < Commit > ( Encoding . UTF8 . GetBytes ( signedCommit ) ) ;
1163
+ var signedId2 = odb . CreateCommitWithSignature ( signedData , signatureData ) ;
1164
+
1165
+ Assert . Equal ( signedId , signedId2 ) ;
1166
+
1167
+ var signatureInfo = Commit . ExtractSignature ( repo , signedId2 ) ;
1168
+ Assert . Equal ( signedData , signatureInfo . SignedData ) ;
1169
+ Assert . Equal ( signatureData , signatureInfo . Signature ) ;
1127
1170
}
1128
1171
}
1129
1172
}
0 commit comments