@@ -18,6 +18,7 @@ import (
1818 . "github.com/onsi/ginkgo"
1919 . "github.com/onsi/gomega"
2020 "github.com/slack-go/slack"
21+
2122 "gorm.io/driver/sqlite"
2223 "gorm.io/gorm"
2324)
@@ -44,7 +45,6 @@ var _ = Describe("/interactive", func() {
4445 }
4546
4647 BeforeEach (func () {
47- httpmock .Activate ()
4848 gdb , err = gorm .Open (sqlite .Open ("file::memory:?cache=shared&dbname=handle_interactive_get" ), & gorm.Config {})
4949 if err != nil {
5050 log .Fatal (err )
@@ -61,7 +61,6 @@ var _ = Describe("/interactive", func() {
6161 serverResponse = doHttpRequest (router , strings .NewReader (requestBody .Encode ()), map [string ]string {"Content-Type" : "application/x-www-form-urlencoded" }, "POST" , "/interactive" )
6262 })
6363 AfterEach (func () {
64- httpmock .DeactivateAndReset ()
6564 db , _ := gdb .DB ()
6665 db .Close ()
6766 })
@@ -99,6 +98,25 @@ var _ = Describe("/interactive", func() {
9998 Expect (msg .DeleteOriginal ).To (BeTrue ())
10099 })
101100 })
101+ Context ("on secret expired" , func () {
102+ BeforeEach (func () {
103+ // Insert the secret with an expired timestamp
104+ tx := gdb .Create (& secretmessage.Secret {
105+ ID : secretIDHashed ,
106+ Value : encryptedPayload ,
107+ ExpiresAt : time .Now ().Add (- time .Hour ), // expired 1 hour ago
108+ })
109+ Expect (tx .RowsAffected ).To (BeEquivalentTo (1 ))
110+ })
111+ It ("should return error message for expired secret" , func () {
112+ var msg slack.Message
113+ b , _ := ioutil .ReadAll (serverResponse .Body )
114+ json .Unmarshal (b , & msg )
115+ Expect (serverResponse .Code ).To (Equal (http .StatusOK ))
116+ Expect (msg .Attachments [0 ].Text ).To (MatchRegexp (`This Secret has expired` ))
117+ Expect (msg .DeleteOriginal ).To (BeTrue ())
118+ })
119+ })
102120 Context ("on db error" , func () {
103121 BeforeEach (func () {
104122 // force an error by closing DB
@@ -161,4 +179,76 @@ var _ = Describe("/interactive", func() {
161179 })
162180 })
163181 })
182+
183+ Describe ("Modal Submit" , func () {
184+ // setup httpmock for responseURl from privatemetadata
185+ responseURL := "https://hooks.slack.com/actions/T00000000/1234567890/abcdefghijklmnopqrstuvwxyz"
186+
187+ interactionPayload := slack.InteractionCallback {
188+ Type : slack .InteractionTypeViewSubmission ,
189+ View : slack.View {
190+ PrivateMetadata : responseURL ,
191+ Type : "modal" ,
192+ CallbackID : "test_modal_submit" ,
193+ State : & slack.ViewState {
194+ Values : map [string ]map [string ]slack.BlockAction {
195+ "secret_text_input" : {
196+ "secret_text_input" : slack.BlockAction {
197+ Value : "example secret text" ,
198+ },
199+ },
200+ "expiry_date_input" : {
201+ "expiry_date_input" : slack.BlockAction {
202+ SelectedDate : "2024-06-01" ,
203+ },
204+ },
205+ },
206+ },
207+ },
208+ }
209+ interactionBytes , err := json .Marshal (interactionPayload )
210+ if err != nil {
211+ log .Fatal (err )
212+ }
213+ requestBody := url.Values {
214+ "payload" : []string {string (interactionBytes )},
215+ }
216+
217+ BeforeEach (func () {
218+ // Configuration
219+ httpmock .Activate ()
220+
221+ gdb , err = gorm .Open (sqlite .Open ("file::memory:?cache=shared&dbname=handle_interactive_delete" ), & gorm.Config {})
222+ if err != nil {
223+ log .Fatal (err )
224+ }
225+ gdb .AutoMigrate (secretmessage.Team {})
226+ gdb .AutoMigrate (secretmessage.Secret {})
227+ ctl = secretmessage .NewController (
228+ secretmessage.Config {SkipSignatureValidation : true },
229+ gdb ,
230+ )
231+
232+ })
233+ JustBeforeEach (func () {
234+ // creation of objects
235+ router = ctl .ConfigureRoutes ()
236+ serverResponse = doHttpRequest (router , strings .NewReader (requestBody .Encode ()), map [string ]string {"Content-Type" : "application/x-www-form-urlencoded" }, "POST" , "/interactive" )
237+ })
238+ AfterEach (func () {
239+ httpmock .DeactivateAndReset ()
240+ db , _ := gdb .DB ()
241+ db .Close ()
242+ })
243+
244+ Context ("on happy path" , func () {
245+ BeforeEach (func () {
246+ httpmock .RegisterResponder ("POST" , responseURL , httpmock .NewStringResponder (200 , `ok` ))
247+
248+ })
249+ It ("should return 200" , func () {
250+ Expect (serverResponse .Code ).To (Equal (http .StatusOK ))
251+ })
252+ })
253+ })
164254})
0 commit comments