| 
									
										
										
										
											2015-03-02 16:58:35 +08:00
										 |  |  | package util | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							|  |  |  | 	"testing" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	. "github.com/smartystreets/goconvey/convey" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func TestEncoding(t *testing.T) { | 
					
						
							|  |  |  | 	Convey("When generating base64 header", t, func() { | 
					
						
							|  |  |  | 		result := GetBasicAuthHeader("grafana", "1234") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-02 19:56:40 +08:00
										 |  |  | 		So(result, ShouldEqual, "Basic Z3JhZmFuYToxMjM0") | 
					
						
							| 
									
										
										
										
											2015-03-02 16:58:35 +08:00
										 |  |  | 	}) | 
					
						
							| 
									
										
										
										
											2015-06-30 15:37:52 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	Convey("When decoding basic auth header", t, func() { | 
					
						
							|  |  |  | 		header := GetBasicAuthHeader("grafana", "1234") | 
					
						
							|  |  |  | 		username, password, err := DecodeBasicAuthHeader(header) | 
					
						
							|  |  |  | 		So(err, ShouldBeNil) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		So(username, ShouldEqual, "grafana") | 
					
						
							|  |  |  | 		So(password, ShouldEqual, "1234") | 
					
						
							|  |  |  | 	}) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-10 00:55:12 +08:00
										 |  |  | 	Convey("When encoding password", t, func() { | 
					
						
							|  |  |  | 		encodedPassword := EncodePassword("iamgod", "pepper") | 
					
						
							|  |  |  | 		So(encodedPassword, ShouldEqual, "e59c568621e57756495a468f47c74e07c911b037084dd464bb2ed72410970dc849cabd71b48c394faf08a5405dae53741ce9") | 
					
						
							|  |  |  | 	}) | 
					
						
							| 
									
										
										
										
											2015-03-02 16:58:35 +08:00
										 |  |  | } |