mirror of
				https://gitlab.crans.org/nounous/ghostream.git
				synced 2025-11-04 15:42:26 +01:00 
			
		
		
		
	Test authentication
This commit is contained in:
		@@ -1 +1,27 @@
 | 
			
		||||
package auth
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"gitlab.crans.org/nounous/ghostream/auth/basic"
 | 
			
		||||
	"gitlab.crans.org/nounous/ghostream/auth/ldap"
 | 
			
		||||
	"testing"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func TestLoadConfiguration(t *testing.T) {
 | 
			
		||||
	_, err := New(&Options{Backend: "bypass"})
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		t.Error("Creating bypass authentication backend failed:", err)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	_, err = New(&Options{Backend: "basic", Basic: basic.Options{Credentials: make(map[string]string)}})
 | 
			
		||||
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		t.Error("Creating basic authentication backend failed:", err)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	_, err = New(&Options{Backend: "ldap", LDAP: ldap.Options{URI: "ldap://127.0.0.1:389", UserDn: "cn=users,dc=example,dc=com"}})
 | 
			
		||||
 | 
			
		||||
	// TODO Maybe start a LDAP server?
 | 
			
		||||
	if err == nil {
 | 
			
		||||
		t.Error("Creating ldap authentication backend successed mysteriously:", err)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1 +1,17 @@
 | 
			
		||||
package basic
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"testing"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func TestBasicLogin(t *testing.T) {
 | 
			
		||||
	basicCredentials := make(map[string]string)
 | 
			
		||||
	basicCredentials["demo"] = "$2b$15$LRnG3eIHFlYIguTxZOLH7eHwbQC/vqjnLq6nDFiHSUDKIU.f5/1H6"
 | 
			
		||||
 | 
			
		||||
	backend, _ := New(&Options{Credentials: basicCredentials})
 | 
			
		||||
	ok, err := backend.Login("demo", "demo")
 | 
			
		||||
	if !ok {
 | 
			
		||||
		t.Error("Error while logging with the basic authentication:", err)
 | 
			
		||||
	}
 | 
			
		||||
	backend.Close()
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1 +1,14 @@
 | 
			
		||||
package bypass
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"testing"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func TestBypassLogin(t *testing.T) {
 | 
			
		||||
	backend, _ := New()
 | 
			
		||||
	ok, err := backend.Login("demo", "demo")
 | 
			
		||||
	if !ok {
 | 
			
		||||
		t.Error("Error while logging with the bypass authentication:", err)
 | 
			
		||||
	}
 | 
			
		||||
	backend.Close()
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user