Exemplo n.º 1
0
func TestLoadConfiguration(t *testing.T) {
	// Load app config
	_, err := configuration.LoadConfig()
	if err != nil {
		t.Errorf("loadDatabase does not pass. Configuration does not load, looking for %v, got %v", nil, err)
	}
}
Exemplo n.º 2
0
func TestSetConfig(t *testing.T) {
	// Load app config
	Config, err := configuration.LoadConfig()
	if err != nil {
		t.Errorf("TestPush.SetConfig: %v", err)
	}
	// Set config in packages
	SetConfig(&Config)
}
Exemplo n.º 3
0
func BenchmarkUpdateHoldingAccount(b *testing.B) {
	config, _ := configuration.LoadConfig()
	SetConfig(&config)

	for n := 0; n < b.N; n++ {
		ti := time.Now()
		sqlTime := int32(ti.Unix())
		_ = updateBankHoldingAccount(decimal.NewFromFloat(0.), sqlTime)
	}
}
Exemplo n.º 4
0
func BenchmarkLoadDatabase(b *testing.B) {
	// Load app config
	Config, _ := configuration.LoadConfig()
	// Set config in packages
	SetConfig(&Config)

	for n := 0; n < b.N; n++ {
		_, _ = loadDatabase()
	}
}
Exemplo n.º 5
0
func BenchmarkCreateRemoveUserPassword(b *testing.B) {
	Config, _ := configuration.LoadConfig()
	SetConfig(&Config)

	user := "******"
	password := "******"

	for n := 0; n < b.N; n++ {
		_, _ = CreateUserPassword(user, password)
		_, _ = RemoveUserPassword(user, password)
	}
}
Exemplo n.º 6
0
func TestUpdateHoldingAccount(t *testing.T) {
	config, _ := configuration.LoadConfig()
	SetConfig(&config)

	ti := time.Now()
	sqlTime := int32(ti.Unix())

	err := updateBankHoldingAccount(decimal.NewFromFloat(0.), sqlTime)
	if err != nil {
		t.Errorf("DoUpdateHoldingAccount does not pass. Looking for %v, got %v", nil, err)
	}
}
Exemplo n.º 7
0
func loadAllConfig(t *testing.T) {
	// Load app config
	Config, err := configuration.LoadConfig()
	if err != nil {
		t.Errorf("loadDatabase does not pass. Configuration does not load, looking for %v, got %v", nil, err)
	}

	// Set config in packages
	accounts.SetConfig(&Config)
	payments.SetConfig(&Config)
	appauth.SetConfig(&Config)
	push.SetConfig(&Config)
}
Exemplo n.º 8
0
func BenchmarkSavePainTransaction(b *testing.B) {
	config, _ := configuration.LoadConfig()
	SetConfig(&config)

	for n := 0; n < b.N; n++ {
		sender := AccountHolder{"accountNumSender", "bankNumSender"}
		receiver := AccountHolder{"accountNumReceiver", "bankNumReceiver"}
		trans := PAINTrans{101, sender, receiver, decimal.NewFromFloat(0.), decimal.NewFromFloat(0.), 10., 10., "Test desc", "approved"}

		_ = savePainTransaction(trans)
		_ = removePainTransaction(trans)
	}
}
Exemplo n.º 9
0
func BenchmarkGetUserFromToken(b *testing.B) {
	Config, _ := configuration.LoadConfig()
	SetConfig(&Config)

	user := "******"
	password := "******"

	for n := 0; n < b.N; n++ {
		_, _ = CreateUserPassword(user, password)
		token, _ := CreateToken(user, password)
		_, _ = GetUserFromToken(token)
		_, _ = RemoveToken(token)
		_, _ = RemoveUserPassword(user, password)
	}
}
Exemplo n.º 10
0
func TestLoadDatabase(t *testing.T) {
	// Load app config
	Config, err := configuration.LoadConfig()
	fmt.Println("Config: ", Config)
	if err != nil {
		t.Errorf("loadDatabase does not pass. Configuration does not load, looking for %v, got %v", nil, err)
	}
	// Set config in packages
	SetConfig(&Config)

	_, err = loadDatabase()

	if err != nil {
		t.Errorf("LoadDatabase does not pass. Looking for %v, got %v", nil, err)
	}
}
Exemplo n.º 11
0
func TestSavePainTransaction(t *testing.T) {
	config, _ := configuration.LoadConfig()
	SetConfig(&config)

	sender := AccountHolder{"accountNumSender", "bankNumSender"}
	receiver := AccountHolder{"accountNumReceiver", "bankNumReceiver"}
	trans := PAINTrans{101, sender, receiver, decimal.NewFromFloat(0.), decimal.NewFromFloat(0.), 10., 10., "Test desc", "approved"}

	err := savePainTransaction(trans)
	if err != nil {
		t.Errorf("DoSavePainTransaction does not pass. Looking for %v, got %v", nil, err)
	}

	err = removePainTransaction(trans)
	if err != nil {
		t.Errorf("DoDeleteAccount does not pass. Looking for %v, got %v", nil, err)
	}
}
Exemplo n.º 12
0
Arquivo: httpApi.go Projeto: BVNK/bank
func RunHttpServer() (err error) {
	bLog(0, "HTTP server called", trace())

	// Load app config
	Config, err := configuration.LoadConfig()
	if err != nil {
		return errors.New("server.runServer: " + err.Error())
	}

	// Set config in packages
	accounts.SetConfig(&Config)
	transactions.SetConfig(&Config)
	appauth.SetConfig(&Config)
	push.SetConfig(&Config)

	router := NewRouter()

	err = http.ListenAndServeTLS(":"+Config.HttpPort, configuration.ImportPath+"certs/"+Config.FQDN+".pem", configuration.ImportPath+"certs/"+Config.FQDN+".key", router)
	//err = http.ListenAndServeTLS(":8443", "certs/thebankoftoday.com.crt", "certs/thebankoftoday.com.key", router)
	fmt.Println(err)
	bLog(4, err.Error(), trace())
	return
}
Exemplo n.º 13
0
Arquivo: main.go Projeto: BVNK/bank
// Simple log function for logging to a file
func bLog(logLevel int, message string, functionName string) (err error) {
	f, err := os.OpenFile("./bvnk.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
	if err != nil {
		log.Fatalf("error opening file: %v", err)
	}
	defer f.Close()

	log.SetOutput(f)

	// Check logLevel
	if logLevel > 4 {
		// Default to highest available to avoid returning errors
		logLevel = 4
	}

	// Load app config
	Config, err := configuration.LoadConfig()
	if err != nil {
		return errors.New("main.bLog: " + err.Error())
	}
	// Check log level based on config
	// logLevel is an int: 0 debug, 1 info, 2 warning, 3 error, 4 critical
	// List of colours: https://radu.cotescu.com/coloured-log-outputs/
	// Default Blue
	colourBegin := "\033[0;34m"
	switch Config.LogLevel {
	case "critical":
		if logLevel < 4 {
			return
		}
		// High intensity red
		colourBegin = "\033[0;91m"
		break
	case "error":
		if logLevel < 3 {
			return
		}
		// Red
		colourBegin = "\033[0;31m"
		break
	case "warning":
		if logLevel < 2 {
			return
		}
		// Yellow
		colourBegin = "\033[0;33m"
		break
	case "info":
		if logLevel < 1 {
			return
		}
		// Cyan
		colourBegin = "\033[0;36m"
		break
	case "debug":
		// Log everything
		break
	}

	colourEnd := "\033[39m"
	// Construct message
	log.Printf("%s%s :: %s%s", colourBegin, message, functionName, colourEnd)
	return
}
Exemplo n.º 14
0
Arquivo: server.go Projeto: BVNK/bank
func runServer(mode string) (message string, err error) {

	// Load app config
	Config, err := configuration.LoadConfig()
	if err != nil {
		return "", errors.New("server.runServer: " + err.Error())
	}

	// Set config in packages
	accounts.SetConfig(&Config)
	transactions.SetConfig(&Config)
	appauth.SetConfig(&Config)
	push.SetConfig(&Config)

	switch mode {
	case "tls":
		cert, err := tls.LoadX509KeyPair(configuration.ImportPath+"certs/server.pem", configuration.ImportPath+"certs/server.key")
		if err != nil {
			return "", err
		}

		// Load config and generate seed
		config := tls.Config{Certificates: []tls.Certificate{cert}, ClientAuth: tls.RequireAnyClientCert}
		config.Rand = rand.Reader

		// Listen for incoming connections.
		l, err := tls.Listen(CONN_TYPE, CONN_HOST+":"+CONN_PORT, &config)
		if err != nil {
			return "", err
		}

		// Close the listener when the application closes.
		defer l.Close()
		bLog(0, "Listening on secure "+CONN_HOST+":"+CONN_PORT, trace())
		for {
			// Listen for an incoming connection.
			conn, err := l.Accept()
			if err != nil {
				return "", err
			}
			// Handle connections in a new goroutine.
			go handleTCPRequest(conn)
		}
	case "no-tls":
		// Listen for incoming connections.
		l, err := net.Listen(CONN_TYPE, CONN_HOST+":"+CONN_PORT)
		if err != nil {
			return "", err
		}

		// Close the listener when the application closes.
		defer l.Close()
		bLog(0, "Listening on unsecure "+CONN_HOST+":"+CONN_PORT, trace())
		for {
			// Listen for an incoming connection.
			conn, err := l.Accept()
			if err != nil {
				return "", err
			}
			// Handle connections in a new goroutine.
			go handleTCPRequest(conn)
		}
	}

	return
}