public IChallengeHandler GetHandler(Challenge c, IReadOnlyDictionary <string, object> initParams) { var h = new AwsS3ChallengeHandler(); if (initParams == null) { initParams = new Dictionary <string, object>(); } // Required params if (!initParams.ContainsKey(BUCKET_NAME.Name)) { throw new KeyNotFoundException($"missing required parameter [{BUCKET_NAME.Name}]"); } h.BucketName = (string)initParams[BUCKET_NAME.Name]; // Optional params if (initParams.ContainsKey(CONTENT_TYPE.Name)) { h.ContentType = (string)initParams[CONTENT_TYPE.Name]; } if (initParams.ContainsKey(CANNED_ACL.Name)) { h.CannedAcl = (string)initParams[CANNED_ACL.Name]; } // Process the common params h.CommonParams.InitParams(initParams); return(h); }
public void TestHandlerUploadAndCleanUpObject() { var r = new Random(); var bn = new byte[10]; var bv = new byte[10]; r.NextBytes(bn); r.NextBytes(bv); var rn = BitConverter.ToString(bn); var rv = BitConverter.ToString(bv); var c = new HttpChallenge(AcmeProtocol.CHALLENGE_TYPE_HTTP, new HttpChallengeAnswer()) { Token = "FOOBAR", FileUrl = $"http://foobar.acmetesting.zyborg.io/utest/{rn}", FilePath = $"/utest/{rn}", FileContent = rv, }; var awsParams = new AwsCommonParams(); awsParams.InitParams(_handlerParams); var p = GetProvider(); using (var h = p.GetHandler(c, _handlerParams)) { // Assert test file does not exist var s3Obj = AwsS3ChallengeHandler.GetFile(awsParams, _handlerParams.BucketName, c.FilePath); // Assert test record does *not* exist Assert.IsNull(s3Obj); // Create the record... h.Handle(c); // ...and assert it does exist s3Obj = AwsS3ChallengeHandler.GetFile(awsParams, _handlerParams.BucketName, c.FilePath); Assert.IsNotNull(s3Obj); using (var sr = new StreamReader(s3Obj.ResponseStream)) { var v = sr.ReadToEnd(); Assert.AreEqual(c.FileContent, v); } // Clean up the record... h.CleanUp(c); // ...and assert it does not exist once more s3Obj = AwsS3ChallengeHandler.GetFile(awsParams, _handlerParams.BucketName, c.FilePath); Assert.IsNull(s3Obj); } }
public IChallengeHandler GetHandler(Challenge c, IReadOnlyDictionary<string, object> initParams) { var h = new AwsS3ChallengeHandler(); if (initParams == null) initParams = new Dictionary<string, object>(); // Required params if (!initParams.ContainsKey(BUCKET_NAME.Name)) throw new KeyNotFoundException($"missing required parameter [{BUCKET_NAME.Name}]"); h.BucketName = (string)initParams[BUCKET_NAME.Name]; // Optional params if (initParams.ContainsKey(CONTENT_TYPE.Name)) h.ContentType = (string)initParams[CONTENT_TYPE.Name]; if (initParams.ContainsKey(CANNED_ACL.Name)) h.CannedAcl = (string)initParams[CANNED_ACL.Name]; // Process the common params h.CommonParams.InitParams(initParams); return h; }